Skip to content

Comments

fix: several bug fixes related to internal use of image_span#5004

Merged
lgritz merged 1 commit intoAcademySoftwareFoundation:mainfrom
lgritz:lg-imagespan
Jan 18, 2026
Merged

fix: several bug fixes related to internal use of image_span#5004
lgritz merged 1 commit intoAcademySoftwareFoundation:mainfrom
lgritz:lg-imagespan

Conversation

@lgritz
Copy link
Collaborator

@lgritz lgritz commented Jan 12, 2026

  • ImageBuf internal buffer span lacked correct chansize. The internal m_bufspan is an image_span<byte>, and as such, it needs to remember the size of the original data type. Otherwise, there's a cascade of potential errors when it thinks that the individual values are byte sized.

  • In both ImageInput and ImageOutput, several sanity checks of image_span size versus expectations were incorrect. They were only checking if the total byte sizes matched expectations, but they are allowed to disagree when you consider type conversions (in which case, it's the total number of values that need to match, not the total byte sizes.

* ImageBuf internal buffer span lacked correct chansize.
  The internal m_bufspan is an `imagespan<byte>`, and as such, it
  needs to remember the size of the original data type. Otherwise,
  there's a cascade of potential errors when it thinks that the
  individual values are byte sized.

* In both ImageInput and ImageOutput, several sanity checks of
  image_span size versus expectations were incorrect. They were only
  checking if the total byte sizes matched expectations, but they are
  allowed to disagree when you consider type conversions (in which
  case, it's the total number of values that need to match, not the
  total byte sizes.

Signed-off-by: Larry Gritz <lg@larrygritz.com>
@lgritz lgritz requested a review from Copilot January 14, 2026 02:44
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR addresses critical bugs in the internal handling of image_span objects across ImageBuf, ImageInput, and ImageOutput classes. The main issue was incorrect size validation when type conversions occur between the data format and the native image format.

Changes:

  • Fixed ImageBuf's internal buffer span initialization to correctly track the channel size of the original data type
  • Replaced inline size validation logic in ImageInput and ImageOutput methods with a centralized check_span_size utility that properly distinguishes between byte-size matching (for unknown types) and value-count matching (for concrete types with potential type conversion)
  • Removed commented-out dead code from ImageInput

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
src/libOpenImageIO/imagebuf.cpp Fixed m_bufspan initialization to include chansize parameter for proper type tracking
src/libOpenImageIO/imageoutput.cpp Added check_span_size utility and refactored all write methods to use correct size validation
src/libOpenImageIO/imageinput.cpp Added check_span_size utility, refactored all read methods to use correct size validation, and removed dead code

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

// total byte size needs to match the "native" size, or the format is
// concrete and the number of value must match (it's ok if the size
// doesn't match, since a data type conversion will occur).
if (datatype.is_unknown()) { // Unknown assumes native chan types
Copy link

Copilot AI Jan 14, 2026

Choose a reason for hiding this comment

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

Corrected spelling of 'chan' to 'channel' in the comment for clarity.

Suggested change
if (datatype.is_unknown()) { // Unknown assumes native chan types
if (datatype.is_unknown()) { // Unknown assumes native channel types

Copilot uses AI. Check for mistakes.
// total byte size needs to match the "native" size, or the format is
// concrete and the number of value must match (it's ok if the size
// doesn't match, since a data type conversion will occur).
if (datatype.is_unknown()) { // Unknown assumes native chan types
Copy link

Copilot AI Jan 14, 2026

Choose a reason for hiding this comment

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

Corrected spelling of 'chan' to 'channel' in the comment for clarity.

Suggested change
if (datatype.is_unknown()) { // Unknown assumes native chan types
if (datatype.is_unknown()) { // Unknown assumes native channel types

Copilot uses AI. Check for mistakes.
@lgritz
Copy link
Collaborator Author

lgritz commented Jan 14, 2026

Any comments about these important bug fixes?

@lgritz
Copy link
Collaborator Author

lgritz commented Jan 18, 2026

No objections -> merging.

@lgritz lgritz merged commit f862c06 into AcademySoftwareFoundation:main Jan 18, 2026
29 checks passed
lgritz added a commit to lgritz/OpenImageIO that referenced this pull request Jan 18, 2026
…SoftwareFoundation#5004)

* ImageBuf internal buffer span lacked correct chansize. The internal
`m_bufspan` is an `image_span<byte>`, and as such, it needs to remember
the size of the original data type. Otherwise, there's a cascade of
potential errors when it thinks that the individual values are byte
sized.

* In both ImageInput and ImageOutput, several sanity checks of
image_span size versus expectations were incorrect. They were only
checking if the total byte sizes matched expectations, but they are
allowed to disagree when you consider type conversions (in which case,
it's the total number of values that need to match, not the total byte
sizes.

Signed-off-by: Larry Gritz <lg@larrygritz.com>
@lgritz lgritz deleted the lg-imagespan branch January 18, 2026 19:53
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.

1 participant