-
Notifications
You must be signed in to change notification settings - Fork 606
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
[BUG] Segfault Due to Logic Error; read negative size #3711
Comments
Thanks, good catch. Here's the fix I a proposing: #3712 |
lgritz
added a commit
to lgritz/OpenImageIO
that referenced
this issue
Dec 17, 2022
IOMemReader::pread catch out-of-range read positions. Fixes AcademySoftwareFoundation#3711 Along the way, I noticed that the system pread & pwrite return a ssize_t rather than a size_t as our IOProxy methods do, so I need to catch the negative value returns that they use to indicate errors.
lgritz
added a commit
to lgritz/OpenImageIO
that referenced
this issue
Dec 17, 2022
IOMemReader::pread catch out-of-range read positions. Fixes AcademySoftwareFoundation#3711 Along the way, I noticed that the system pread & pwrite return a ssize_t rather than a size_t as our IOProxy methods do, so I need to catch the negative value returns that they use to indicate errors.
lgritz
added a commit
that referenced
this issue
Dec 18, 2022
IOMemReader::pread catch out-of-range read positions. Fixes #3711 Along the way, I noticed that the system pread & pwrite return a ssize_t rather than a size_t as our IOProxy methods do, so I need to catch the negative value returns that they use to indicate errors.
lgritz
added a commit
to lgritz/OpenImageIO
that referenced
this issue
Dec 18, 2022
…tion#3712) IOMemReader::pread catch out-of-range read positions. Fixes AcademySoftwareFoundation#3711 Along the way, I noticed that the system pread & pwrite return a ssize_t rather than a size_t as our IOProxy methods do, so I need to catch the negative value returns that they use to indicate errors.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Describe the bug
I'm using a IOMemReader with an ImageInput to parse an image. When doing this I sometimes get segfaults because of a logic error causing a negative memcpy. The problem is in src/libutil/filesystem.cpp in the Filesystem::IOMemReader::pread routine. There's an if to check if the read will exceed the buffer size. The problem is with the change to size. If offset somehow becomes greater than m_buf.size(), then size becomes negative; well, really big because it's unsigned. I would guess that the m_pos became greater than m_buf.size() because the seek operation does not validate offset against the size.
To Reproduce
Steps to reproduce the behavior:
Expected behavior
The file should open without errors.
Evidence
Platform information:
Fix:
This is the quick fix I tested to verify the problem. A better fix might be to validate the seek offset. Both issues should probably be fixed. I'm not sure how you would want to handle this error. At least this code will show you how to catch the problem.
The text was updated successfully, but these errors were encountered: