Skip to content

Conversation

@kkaefer
Copy link
Member

@kkaefer kkaefer commented Jul 11, 2025

A truncated buffer could lead to an out of bounds memory access when calling get_bool(). Instead of checking the buffer before we are accessing the first byte beyond the end of the before, we first read it and then checked it. This change reverses the actions so that no out-of-bounds read occurs.

We have not found this bug in our previous fuzzing because of the way we read the test data: std::string always adds a trailing NUL byte so that it can be trivially converted to a C string. Technically, this trailing NUL byte is part of the buffer, but is not returned as part of the buffer length. Therefore, accessing a single byte beyond the end of the buffer did not trigger the address sanitizer.

@kkaefer kkaefer requested a review from joto July 11, 2025 14:23
@kkaefer kkaefer added the bug label Jul 11, 2025
A truncated buffer could lead to an out of bounds memory access. Instead of checking the buffer before we are accessing the first byte beyond the end of the before, we first read it and _then_ checked it. This change reverses the actions so that no out-of-bounds read occurs.

We have not found this bug in our previous fuzzing because of the way we read the test data: std::string always adds a trailing 0 byte so that it can be trivially converted to a C string. Technically, this trailing 0 byte is part of the buffer, but is not returned as part of the buffer length. Therefore, accessing a single byte beyond the end of the buffer did not trigger the address sanitizer.
Copy link
Collaborator

@joto joto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch! Looks good to me.

@joto joto merged commit 67e3247 into master Jul 15, 2025
56 checks passed
@kkaefer kkaefer deleted the kk/bool-overrun branch July 15, 2025 16:00
artemp added a commit to mapnik/mapnik that referenced this pull request Jul 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants