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 #3950: Div by 0 during DXT4 DDS load #3959

Merged
merged 4 commits into from
Aug 25, 2023

Conversation

jessey-git
Copy link
Contributor

Description

Fix the div-by-0 when handling unassociated alpha during a DXT4 DDS load. The code mirrors what other formats do by first checking to see if the alpha value is not 0 before continuing.

Tests

Added the 218-byte file from the bug to the local test suite.

Checklist:

  • I have read the contribution guidelines.
  • I have updated the documentation, if applicable.
  • I have ensured that the change is tested somewhere in the testsuite
    (adding new test cases if necessary).
  • If I added or modified a C++ API call, I have also amended the
    corresponding Python bindings (and if altering ImageBufAlgo functions, also
    exposed the new functionality as oiiotool options).
  • My code follows the prevailing code style of this project. If I haven't
    already run clang-format before submitting, I definitely will look at the CI
    test that runs clang-format and fix anything that it highlights as being
    nonconforming.

Signed-off-by: Jesse Yurkovich <jesse.y@gmail.com>
Signed-off-by: Jesse Yurkovich <jesse.y@gmail.com>
Signed-off-by: Jesse Yurkovich <jesse.y@gmail.com>
@jessey-git
Copy link
Contributor Author

There's a secondary failure after the initial one hit in the report. I'll need a bit more time to test out the fix.

The failure is that the file declares itself as a DXT4, which has alpha (4 channel), but it also has its "normal map" flag set. This confuses the code inside GetChannelCount as "normal map" takes precedence and returns 3 for the count instead of 4. This causes OIIO to allocate fewer bytes than required and ASAN rightfully flags the problem when the code eventually writes past the buffer.

Signed-off-by: Jesse Yurkovich <jesse.y@gmail.com>
@lgritz
Copy link
Collaborator

lgritz commented Aug 25, 2023

Is this ready to review, @jessey-git ?

@jessey-git
Copy link
Contributor Author

Yes, I believe so.

Copy link
Collaborator

@lgritz lgritz left a comment

Choose a reason for hiding this comment

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

LGTM

@lgritz lgritz merged commit a5c7a0c into AcademySoftwareFoundation:master Aug 25, 2023
23 checks passed
@lgritz
Copy link
Collaborator

lgritz commented Aug 25, 2023

Fixes #3950

lgritz pushed a commit to lgritz/OpenImageIO that referenced this pull request Aug 25, 2023
…n#3959)

Fixes AcademySoftwareFoundation#3950

Fix the div-by-0 when handling unassociated alpha during a DXT4 DDS
load. The code mirrors what other formats do by first checking to see if
the alpha value is not 0 before continuing.

Added the 218-byte file from the bug to the local test suite.

---------

Signed-off-by: Jesse Yurkovich <jesse.y@gmail.com>
@jessey-git jessey-git deleted the fix3950 branch September 26, 2023 02:48
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.

None yet

2 participants