Skip to content

fix out-of-bounds read when matching IFS header keywords - #6486

Open
aysha-afrah26 wants to merge 2 commits into
PointCloudLibrary:masterfrom
aysha-afrah26:ifs-keyword-bounds
Open

aysha-afrah26 wants to merge 2 commits into
PointCloudLibrary:masterfrom
aysha-afrah26:ifs-keyword-bounds

Conversation

@aysha-afrah26

Copy link
Copy Markdown

The strings in an IFS header are length prefixed, and IFSReader::readHeader copies each one into a new char[] sized by that prefix before handing it to strcmp. The prefix comes straight from the file, so nothing guarantees it covers the terminating null character that IFSWriter appends, and on a header that leaves it out strcmp walks off the end of the allocation. I noticed the mismatch while reading the reader against the writer and confirmed it under ASan: a file storing its magic as length 3 followed by the bytes IFS gives a heap-buffer-overflow read on the magic comparison, and the VERTICES keyword in the header loop and the TRIANGLES keyword on the mesh path behave the same way. Routing the three comparisons through a small helper that compares only the characters it actually read keeps the parse inside the buffer, and since the helper consumes the field even when it does not match, the stream stays aligned for the next element. The cloud name was being copied into a file-sized allocation only to be thrown away, so it now skips the bytes instead. Keywords are still accepted with or without the trailing null so existing files keep loading, and the test covers both the cloud and the mesh entry point.

The length prefix of the strings in an IFS header comes from the file and
need not cover the terminating null character, so comparing the buffer
with strcmp can read past its end. Compare only the characters that were
actually read instead.
Comment thread test/io/test_io.cpp Outdated
append_bytes (&value, sizeof (value));
};
// Write the string without the terminating null character a writer would add
const auto append_unterminated = [&data, &append_bytes, &append_uint32] (const std::string& str)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
const auto append_unterminated = [&data, &append_bytes, &append_uint32] (const std::string& str)
const auto append_unterminated = [&append_bytes, &append_uint32] (const std::string& str)

&data was not used and thats why it failed on MacOS.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Good catch, that's it. data only gets touched through append_bytes, so capturing it directly was dead weight and -Wunused-lambda-capture flagged it under -Werror on the clang macOS jobs (the Ubuntu ones don't set -Werror, which is why they stayed green).

Applied your suggestion in 644ca49. Reproduced it locally with Apple clang and the macOS CI flags first: test/io/test_io.cpp:1853: error: lambda capture 'data' is not used before, clean after, and the test still passes under ASan for both the cloud and the mesh path.

The append_unterminated lambda captured data without using it, which
-Wunused-lambda-capture rejects under -Werror on the clang macOS builds.
@mvieth mvieth added module: io changelog: fix Meta-information for changelog generation labels Oct 11, 2026

@mvieth mvieth left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks good to me, thanks

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

changelog: fix Meta-information for changelog generation module: io

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants