Skip to content

Commit ef8cfd2

Browse files
Fix Deep Scanline Input crash when using a framebuffer as parameter (AcademySoftwareFoundation#2019)
* Fix Deep Scanline Input crash when using an externally allocated framebuffer The Deep Scanline Input code has recently been rewritten to make use of the EXR core library. As a result a bug was introduced when using the overloads of readPixels() and readPixelSampleCounts() that use externally provided framebuffers as parameters, a hard crash was occuring. According to the comment on the header of these functions, when these overloads are used the InputFile's frameBuffer is not used. However both these functions call into readMemData(), which does use the InputFile's member framebuffer, which has not been allocated, resulting into a segmentation fault. This commit fixes the above issue, by using the parameter framebuffer that is passed in, which should be allocated by the caller application. Signed-off-by: Nikolaos Koutsikos <nikolaos.koutsikos@foundry.com> * Add a Deep Scanline Input test that uses a framebuffer parameter After having found a bug with the readPixels() and readPixelSampleCounts() overloads that receive a framebuffer parameter, it was made apparent that there was a hole in our tests to cover these functions. This commits slightly refactors the DeepScanLineBasic tests and adds a third read path to add coverage for this case as well. Signed-off-by: Nikolaos Koutsikos <nikolaos.koutsikos@foundry.com> --------- Signed-off-by: Nikolaos Koutsikos <nikolaos.koutsikos@foundry.com>
1 parent d0e2e53 commit ef8cfd2

File tree

2 files changed

+43
-10
lines changed

2 files changed

+43
-10
lines changed

src/lib/OpenEXR/ImfDeepScanLineInputFile.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -629,7 +629,7 @@ DeepScanLineInputFile::Data::readMemData (
629629
*_ctxt,
630630
partNumber,
631631
rawPixelData,
632-
&frameBuffer,
632+
&fb,
633633
scanLine1,
634634
scanLine2,
635635
fills);

src/test/OpenEXRTest/testDeepScanLineBasic.cpp

Lines changed: 42 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -243,11 +243,18 @@ generateRandomFile (
243243
}
244244
}
245245

246+
enum ReadType
247+
{
248+
eReadBulk = 1,
249+
eReadScanline,
250+
eReadScanlinelFrameBuffer
251+
};
252+
246253
void
247254
readFile (
248255
const std::string& filename,
249256
int channelCount,
250-
bool bulkRead,
257+
ReadType readType,
251258
bool randomChannels)
252259
{
253260
if (randomChannels) { cout << " reading random channels " << flush; }
@@ -352,9 +359,12 @@ readFile (
352359
pointerSize * width, // yStride// 10
353360
sampleSize)); // sampleStride
354361
}
355-
file.setFrameBuffer (frameBuffer);
362+
if (readType != eReadScanlinelFrameBuffer)
363+
{
364+
file.setFrameBuffer (frameBuffer);
365+
}
356366

357-
if (bulkRead)
367+
if (readType == eReadBulk)
358368
{
359369
cout << "bulk " << flush;
360370
file.readPixelSampleCounts (dataWindow.min.y, dataWindow.max.y);
@@ -397,10 +407,24 @@ readFile (
397407
else
398408
{
399409
cout << "per-line " << flush;
410+
if (readType == eReadScanlinelFrameBuffer) cout << "framebuffer " << flush;
400411
for (int i = 0; i < dataWindow.max.y - dataWindow.min.y + 1; i++)
401412
{
402413
int y = i + dataWindow.min.y;
403-
file.readPixelSampleCounts (y);
414+
vector<char> buffer;
415+
if (readType == eReadScanlinelFrameBuffer)
416+
{
417+
uint64_t pixSize = 0;
418+
file.rawPixelData (y, nullptr, pixSize);
419+
buffer.resize (pixSize);
420+
file.rawPixelData (y, buffer.data(), pixSize);
421+
file.readPixelSampleCounts (buffer.data(), frameBuffer, y, y);
422+
}
423+
else // readType == eReadScanline
424+
{
425+
file.readPixelSampleCounts (y);
426+
}
427+
404428

405429
for (int j = 0; j < width; j++)
406430
assert (localSampleCount[i][j] == sampleCount[i][j]);
@@ -431,7 +455,14 @@ readFile (
431455
}
432456
}
433457

434-
file.readPixels (y);
458+
if (readType == eReadScanlinelFrameBuffer)
459+
{
460+
file.readPixels (buffer.data(), frameBuffer, y, y);
461+
}
462+
else // readType == eReadScanline
463+
{
464+
file.readPixels (y);
465+
}
435466
}
436467
}
437468

@@ -539,8 +570,10 @@ readWriteTest (
539570
false,
540571
dataWindow,
541572
displayWindow);
542-
readFile (filename, channelCount, false, false);
543-
if (channelCount > 1) readFile (filename, channelCount, false, true);
573+
readFile (filename, channelCount, eReadScanline, false);
574+
if (channelCount > 1) readFile (filename, channelCount, eReadScanline, true);
575+
readFile (filename, channelCount, eReadScanlinelFrameBuffer, false);
576+
if (channelCount > 1) readFile (filename, channelCount, eReadScanlinelFrameBuffer, true);
544577
remove (filename.c_str ());
545578
cout << endl << flush;
546579

@@ -551,8 +584,8 @@ readWriteTest (
551584
true,
552585
dataWindow,
553586
displayWindow);
554-
readFile (filename, channelCount, true, false);
555-
if (channelCount > 1) readFile (filename, channelCount, true, true);
587+
readFile (filename, channelCount, eReadBulk, false);
588+
if (channelCount > 1) readFile (filename, channelCount, eReadBulk, true);
556589
remove (filename.c_str ());
557590
cout << endl << flush;
558591
}

0 commit comments

Comments
 (0)