Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: broken pgm having memory access error #4559

Merged
merged 1 commit into from
Dec 10, 2024

Conversation

lgritz
Copy link
Collaborator

@lgritz lgritz commented Dec 5, 2024

Fixes #4552
Caught during fuzzing with address sanitizer.

The source of the problem was a corrupted/truncated pgm file. Several minor modifications in this PR shore up various cascading errors that followed. Not all were directly causal to the sanitizer trigger, in some cases I fixed what appeared to be related areas.

  • In imagebuf.cpp, any time we free the local pixel memory m_pixels, also explicitly clear the m_bufspan that has a span representation of the usable memory and its bounds.
  • An extra check related to oiiotool --printstats to make sure that the image is valid before passing along to stats collection.
  • In pnminput.cpp, a better error message when we hit a premature end of file.

With these fixes in place, we seem to get a graceful error message and exit when running the POC that was provided with the bug report.

…ion#4561)

Fixes AcademySoftwareFoundation#4553

Caught during fuzzing with address sanitizer. The file appeared to have
a resolution so big it would not be able to satisfy the memory
allocation.

Solution: add the check_open to take an early abort if resolutions are
bigger than could possibly be valid.

Also have Strutil::stoi hande 32 bit overflow without UB overflow that
the sanitizer complains about (that was the other cascading error that
this same test case encountered in the sanitizer after the bad
allocation).

Signed-off-by: Larry Gritz <[email protected]>
Copy link
Contributor

@jessey-git jessey-git left a comment

Choose a reason for hiding this comment

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

LGTM and fixes the ASAN error when testing out locally.

@lgritz lgritz merged commit 34b29f3 into AcademySoftwareFoundation:main Dec 10, 2024
29 checks passed
@lgritz lgritz deleted the lg-ppm branch December 17, 2024 00:13
lgritz added a commit to lgritz/OpenImageIO that referenced this pull request Dec 23, 2024
…#4559)

Fixes AcademySoftwareFoundation#4552
Caught during fuzzing with address sanitizer.

The source of the problem was a corrupted/truncated pgm file. Several
minor modifications in this PR shore up various cascading errors that
followed. Not all were directly causal to the sanitizer trigger, in some
cases I fixed what appeared to be related areas.

* In imagebuf.cpp, any time we free the local pixel memory m_pixels,
also explicitly clear the m_bufspan that has a span representation of
the usable memory and its bounds.
* An extra check related to oiiotool --printstats to make sure that the
image is valid before passing along to stats collection.
* In pnminput.cpp, a better error message when we hit a premature end of
file.

With these fixes in place, we seem to get a graceful error message and
exit when running the POC that was provided with the bug report.

Signed-off-by: Larry Gritz <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG]heap-buffer-overflow at src/include/OpenImageIO/fmath.h:983 in openimageio
2 participants