Skip to content

Commit

Permalink
fix(raw): Avoid buffer overrun for flip direction cases
Browse files Browse the repository at this point in the history
If you are looping i over range [0,width), and want index to go the
other direction, you need `index = width - 1 - i`, not
`index = width - i`.

Identified by Sonar static analysis.

Signed-off-by: Larry Gritz <[email protected]>
  • Loading branch information
lgritz committed Dec 31, 2023
1 parent 934eabc commit 9ea1b33
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/raw.imageio/rawinput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1505,7 +1505,7 @@ RawInput::read_native_scanline(int subimage, int miplevel, int y, int /*z*/,
// to the array direction so we must copy the pixels into a temporary contiguous buffer
else if (sizes.flip == 5 /*90 degrees CCW*/
|| sizes.flip == 6 /*90 degrees CW*/) {
scanline_start = m_spec.height - y + sizes.left_margin;
scanline_start = m_spec.height - 1 - y + sizes.left_margin;
if (sizes.flip == 6) {
scanline_start = y + sizes.left_margin;
}
Expand All @@ -1514,7 +1514,7 @@ RawInput::read_native_scanline(int subimage, int miplevel, int y, int /*z*/,
size_t index
= (sizes.flip == 5)
? i
: m_spec.width
: m_spec.width - 1
- i; //flip the index if rotating 90 degrees CW
buffer[index] = (m_processor->imgdata.rawdata.raw_image
+ offset)[sizes.raw_width * i + scanline_start];
Expand Down

0 comments on commit 9ea1b33

Please sign in to comment.