Skip to content

Commit

Permalink
Move buffer size check to base class.
Browse files Browse the repository at this point in the history
Refine size calculation.
  • Loading branch information
MarkCallow committed Dec 29, 2023
1 parent 29255c5 commit dab91cf
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 8 deletions.
4 changes: 3 additions & 1 deletion tools/imageio/imageinput.cc
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,9 @@ ImageInput::readImage(void* pBuffer, size_t bufferByteCount,
{
const auto& targetFormat = format.isUnknown() ? spec().format() : format;
size_t outScanlineByteCount
= targetFormat.basic.bytesPlane0 * spec().width();
= targetFormat.pixelByteCount() * spec().width();
if (bufferByteCount < outScanlineByteCount * spec().height())
throw buffer_too_small();

uint8_t* pDst = static_cast<uint8_t*>(pBuffer);
for (uint32_t y = 0; y < spec().height(); y++) {
Expand Down
8 changes: 1 addition & 7 deletions tools/imageio/jpg.imageio/jpginput.cc
Original file line number Diff line number Diff line change
Expand Up @@ -362,16 +362,10 @@ void JpegInput::readImage(void* bufferOut, size_t bufferByteCount,
uint subimage, uint miplevel,
const FormatDescriptor& format)
{
const auto& targetFormat = format.isUnknown() ? spec().format() : format;
size_t outImageByteCount
= targetFormat.basic.bytesPlane0 * spec().width() * spec().height();
if (bufferByteCount < outImageByteCount)
throw buffer_too_small();

pJd->begin_decoding();
decodingBegun = true;
ImageInput::readImage(bufferOut, bufferByteCount,
subimage, miplevel,
targetFormat);
format);
}

0 comments on commit dab91cf

Please sign in to comment.