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

Prevent infinite loop in bit_range_convert #3996

Merged
merged 1 commit into from
Sep 26, 2023

Conversation

jessey-git
Copy link
Contributor

Description

It was possible for bit_range_convert to be called with a 0 for the FROM_BITS parameter leading to an infinite loop in its processing.

Fixes #3993

Tests

The test image from the above bug is now able to be read correctly.

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>
@@ -1229,6 +1229,7 @@ convert_type (const S &src)
/// shifted fully to the right.
template<unsigned int FROM_BITS, unsigned int TO_BITS>
inline OIIO_HOSTDEVICE unsigned int bit_range_convert(unsigned int in) {
static_assert(FROM_BITS > 0, "FROM_BITS cannot be 0");
Copy link
Collaborator

Choose a reason for hiding this comment

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

The static_assert makes it impossible to successfullyinstantiate the template with FROM_BITS == 0. So why is the if (FROM_BITS) necessary later on?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There's 2 variations of bit_range_convert (1 template and 1 normal) and I suspect you're looking at the wrong one from the diff?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Oh, right you are. My brain thought I was just looking later in the same template. My bad.

@lgritz lgritz merged commit 822304b into AcademySoftwareFoundation:master Sep 26, 2023
24 checks passed
lgritz pushed a commit to lgritz/OpenImageIO that referenced this pull request Sep 27, 2023
…ation#3996)

It was possible for `bit_range_convert` to be called with a 0 for the
`FROM_BITS` parameter leading to an infinite loop in its processing.

Fixes AcademySoftwareFoundation#3993: OIIO library freezes when loading R16G16 uncompressed DDS files

The test image from the above bug is now able to be read correctly.

Signed-off-by: Jesse Yurkovich <jesse.y@gmail.com>
lgritz pushed a commit to lgritz/OpenImageIO that referenced this pull request Sep 27, 2023
…ation#3996)

It was possible for `bit_range_convert` to be called with a 0 for the
`FROM_BITS` parameter leading to an infinite loop in its processing.

Fixes AcademySoftwareFoundation#3993: OIIO library freezes when loading R16G16 uncompressed DDS files

The test image from the above bug is now able to be read correctly.

Signed-off-by: Jesse Yurkovich <jesse.y@gmail.com>
@jessey-git jessey-git deleted the fixbitconvert branch March 11, 2024 05:22
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] OIIO library freezes when loading R16G16 uncompressed DDS files
2 participants