Skip to content

Fill yTileCoords slices tile-relative in InputFile tiled reads - #2879

Open
Dilshad-Tanvi wants to merge 3 commits into
AcademySoftwareFoundation:mainfrom
Dilshad-Tanvi:inputfile-tilecoords-fill
Open

Dilshad-Tanvi wants to merge 3 commits into
AcademySoftwareFoundation:mainfrom
Dilshad-Tanvi:inputfile-tilecoords-fill

Conversation

@Dilshad-Tanvi

Copy link
Copy Markdown
Contributor

InputFile reads scan lines of a tiled part through a one-row tile cache in bufferedReadPixels(). Channels that are in the file go through copyCachedBuffer() with yStart = tileRange.min.y, so a slice with yTileCoords set is addressed relative to the first line of the current row of tiles. That is the same convention TiledInputFile uses, and the whole-image readPixels() shortcut inherits it. Channels missing from the file go through fillBuffer(), which was passed dataWindow.min.y instead. A yTileCoords fill slice was therefore addressed from the top of the data window, and a frame buffer sized for one row of tiles is written past its end as soon as a line in the second row of tiles is read. Reading a 16x12 HALF file with 8x4 tiles line by line into 4-row yTileCoords slices, with a missing Z channel, gives an ASan heap-buffer-overflow WRITE in fillBuffer (ImfInputFile.cpp:721), 0 bytes after the 128-byte fill buffer.

Pass tileRange.min.y to fillBuffer(), matching copyCachedBuffer(). Slices without yTileCoords don't use yStart, so they are unchanged. The new testTileCoordsFill in testScanLineApi.cpp fails without the fix. It is placed away from the testScanLineApi.cpp hunk in #2878, so the two merge cleanly.

InputFile reads scan lines of a tiled part through a one-row tile
cache. Channels in the file are copied to yTileCoords slices relative
to the first line of the current row of tiles, but fill channels were
written relative to the top of the data window, so a frame buffer
sized for one row of tiles was written past its end from the second
row of tiles on. Pass the tile row's first line to fillBuffer() too.

Signed-off-by: Dilshad Tanveer <dilshad@labs.digiscrypt.com>
}

for (int y = 0; y < TY; ++y)
in.readPixels (DY + ty * TY + y);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The overall change seems sound to me.
Could you increase test coverage here to try readPixels calls that read a "slice" of more than one scanline at once? The entire read code could iterate multiple times with different size "slices". You could also test reading the file backwards, so the first scanline accessed in a row of tiles isn't the topmost row.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Makes sense. The test now walks the data window in ranges of 1 to 4 lines (the tile height), forwards and backwards, so the 3-line ranges straddle rows of tiles and going backwards means the first line touched in a row of tiles is its bottom one. It tracks what each row of the one-tile-row buffers should hold and checks all of them after every readPixels call, so untouched rows are confirmed to stay put as well. Still fails under ASan in fillBuffer without the one-line change and passes with it.

Walk the data window in ranges of 1 to TY scan lines, forwards and
backwards, instead of one line at a time, so readPixels() ranges
straddle rows of tiles and the first line accessed in a row of tiles
isn't always its topmost line. Check the whole one-tile-row buffers
after every call.

Signed-off-by: Dilshad Tanveer <dilshad@labs.digiscrypt.com>
{
for (int step = 1; step <= TY; ++step)
{
for (int y = 0; y < TY; ++y)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

it would be more thorough to move the InputFile creation and in.setFrameBuffer call here, so a clean InputFile object is used for each read test

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good point, the cache state was carrying over between passes. Moved the InputFile and setFrameBuffer in there, so each direction/range-size pass now reads through a fresh object with an empty tile cache. Still clean under ASan with the fix and still an overflow in fillBuffer without it.

Move the InputFile construction and setFrameBuffer() call inside the
loop over read directions and range sizes, so every pass starts from
an empty tile cache instead of inheriting the previous pass's state.

Signed-off-by: Dilshad Tanveer <dilshad@labs.digiscrypt.com>

This branch has not been deployed

No deployments
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.

2 participants