forked from AcademySoftwareFoundation/OpenImageIO
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(openexr): Fix out-of-bounds reads when using OpenEXR decreasingY …
…lineOrder. (AcademySoftwareFoundation#4215) This change fixes out-of-bounds reads and incorrect scanline ordering when OpenEXR's decreasingY lineOrder mode is used. OpenEXR expects to process scanlines in decreasing order when the decreasingY lineOrder option is enabled. This change fixes the code that provides the chunks of scanlines to OpenEXR so that the proper scanlines are available when it accesses the FrameBuffer OIIO created. The old code was providing incorrect scanlines AND setting up the FrameBuffer with incorrect pointers so out-of-bounds reads were occurring. The key things to keep in mind are: - Chunks of scanlines need to be sent to OpenEXROutput::write_scanlines() from the bottom of the image to the top when decreasingY is enabled. If the chunk's scanline range does not contain the scanlines OpenEXR is expecting to fetch, then it can cause out-of-bound reads because the wrong information is used to construct the pointers for the Slices created when constructing a FrameBuffer. - OpenEXROutput::write_scanlines() does its own chunking of scanlines and this logic must also properly start from the bottom of the chunk data passed into this function when decreasingY is enabled. - The to_native_rectangle() call in OpenEXROutput::write_scanlines() may return a pointer to m_scratch if a format conversion is needed. This means the pointers passed to OpenEXR, in this situation, _WILL NOT_ be a full frame buffer. This caused OpenEXR to do out-of-bounds reads because the computations used to create the Slices were using the wrong scanline number to adjust the pointer. - The progress callback computation needed to be modified to handle traversing scanlines in decreasing order. I added an openexr-decreasingY test to verify that the code no longer crashes because of the out-of-bound reads and it also verifies that the decreasingY images match the increasingY images. --------- Signed-off-by: Aaron Colwell <[email protected]>
- Loading branch information
Showing
6 changed files
with
180 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
Reading ref/decreasingY-resize.exr | ||
ref/decreasingY-resize.exr : 4080 x 3072, 3 channel, half openexr | ||
SHA-1: 34A9F9879CD89E718ABCEE718A779035F6F78666 | ||
channel list: R, G, B | ||
compression: "zip" | ||
DateTime: "2013:04:16 10:20:35" | ||
Orientation: 1 (normal) | ||
PixelAspectRatio: 1 | ||
ResolutionUnit: "in" | ||
screenWindowCenter: 0, 0 | ||
screenWindowWidth: 1 | ||
Software: "OpenImageIO 2.6.2.0dev : oiiotool ../common/tahoe-tiny.tif --resize 4080x3072 -o ref/decreasingY-resize.exr" | ||
XResolution: 72 | ||
YResolution: 72 | ||
Exif:ImageHistory: "oiiotool ../common/tahoe-tiny.tif --resize 4080x3072 -o ref/decreasingY-resize.exr" | ||
oiio:ColorSpace: "Linear" | ||
oiio:subimages: 1 | ||
Reading ref/decreasingY-copy.exr | ||
ref/decreasingY-copy.exr : 4080 x 3072, 3 channel, half openexr | ||
SHA-1: 34A9F9879CD89E718ABCEE718A779035F6F78666 | ||
channel list: R, G, B | ||
compression: "zip" | ||
DateTime: "2013:04:16 10:20:35" | ||
Orientation: 1 (normal) | ||
PixelAspectRatio: 1 | ||
ResolutionUnit: "in" | ||
screenWindowCenter: 0, 0 | ||
screenWindowWidth: 1 | ||
Software: "OpenImageIO 2.6.2.0dev : oiiotool ref/decreasingY-resize.exr -o ref/decreasingY-copy.exr" | ||
XResolution: 72 | ||
YResolution: 72 | ||
Exif:ImageHistory: "oiiotool ../common/tahoe-tiny.tif --resize 4080x3072 -o ref/decreasingY-resize.exr | ||
oiiotool ref/decreasingY-resize.exr -o ref/decreasingY-copy.exr" | ||
oiio:ColorSpace: "Linear" | ||
oiio:subimages: 1 | ||
Reading decreasingY-resize.exr | ||
decreasingY-resize.exr : 4080 x 3072, 3 channel, half openexr | ||
SHA-1: 34A9F9879CD89E718ABCEE718A779035F6F78666 | ||
channel list: R, G, B | ||
compression: "zip" | ||
DateTime: "2013:04:16 10:20:35" | ||
Orientation: 1 (normal) | ||
PixelAspectRatio: 1 | ||
ResolutionUnit: "in" | ||
screenWindowCenter: 0, 0 | ||
screenWindowWidth: 1 | ||
Software: "OpenImageIO 2.6.2.0dev : oiiotool ../common/tahoe-tiny.tif --resize 4080x3072 --attrib openexr:lineOrder decreasingY -o decreasingY-resize.exr" | ||
XResolution: 72 | ||
YResolution: 72 | ||
Exif:ImageHistory: "oiiotool ../common/tahoe-tiny.tif --resize 4080x3072 --attrib openexr:lineOrder decreasingY -o decreasingY-resize.exr" | ||
oiio:ColorSpace: "Linear" | ||
oiio:subimages: 1 | ||
Reading decreasingY-copy.exr | ||
decreasingY-copy.exr : 4080 x 3072, 3 channel, half openexr | ||
SHA-1: 34A9F9879CD89E718ABCEE718A779035F6F78666 | ||
channel list: R, G, B | ||
compression: "zip" | ||
DateTime: "2013:04:16 10:20:35" | ||
Orientation: 1 (normal) | ||
PixelAspectRatio: 1 | ||
ResolutionUnit: "in" | ||
screenWindowCenter: 0, 0 | ||
screenWindowWidth: 1 | ||
Software: "OpenImageIO 2.6.2.0dev : oiiotool ref/decreasingY-resize.exr --attrib openexr:lineOrder decreasingY -o decreasingY-copy.exr" | ||
XResolution: 72 | ||
YResolution: 72 | ||
Exif:ImageHistory: "oiiotool ../common/tahoe-tiny.tif --resize 4080x3072 -o ref/decreasingY-resize.exr | ||
oiiotool ref/decreasingY-resize.exr --attrib openexr:lineOrder decreasingY -o decreasingY-copy.exr" | ||
oiio:ColorSpace: "Linear" | ||
oiio:subimages: 1 | ||
Comparing "decreasingY-resize.exr" and "ref/decreasingY-resize.exr" | ||
PASS | ||
Comparing "decreasingY-copy.exr" and "ref/decreasingY-copy.exr" | ||
PASS |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#!/usr/bin/env python | ||
|
||
# Copyright Contributors to the OpenImageIO project. | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# https://github.com/AcademySoftwareFoundation/OpenImageIO | ||
|
||
import os, sys | ||
|
||
#################################################################### | ||
# Verify decreasingY line order generates same image as increasingY (default). | ||
#################################################################### | ||
|
||
# Capture error output | ||
redirect = " >> out.txt 2>&1 " | ||
|
||
# Create reference images stored in increasingY order (default) | ||
# Resizing to a large image size to ensure scanline chunking logic is triggered. | ||
command += oiiotool("../common/tahoe-tiny.tif --resize 4080x3072 -o ref/decreasingY-resize.exr") | ||
command += info_command("ref/decreasingY-resize.exr") | ||
command += oiiotool("ref/decreasingY-resize.exr -o ref/decreasingY-copy.exr") | ||
command += info_command("ref/decreasingY-copy.exr") | ||
|
||
# Create an image in decreasing order via resizing (Tests ImageOutput::write_image() logic) | ||
command += oiiotool("../common/tahoe-tiny.tif --resize 4080x3072 --attrib openexr:lineOrder decreasingY -o decreasingY-resize.exr") | ||
command += info_command("decreasingY-resize.exr") | ||
|
||
# Create an image in decreasing order via copying a reference image. (Tests ImageBuf::write() logic) | ||
command += oiiotool("ref/decreasingY-resize.exr --attrib openexr:lineOrder decreasingY -o decreasingY-copy.exr") | ||
command += info_command("decreasingY-copy.exr") | ||
|
||
# Outputs to check against references. | ||
# This makes sure the images look the same since the line order is a storage detail and should not | ||
# change how the image actually looks. These comparisons help verify chunk order and scanlines are | ||
# processed properly. | ||
outputs = [ | ||
"decreasingY-resize.exr", | ||
"decreasingY-copy.exr", | ||
] | ||
|
||
|
||
#print "Running this command:\n" + command + "\n" |