Skip to content

Commit

Permalink
Use rgb.rowBytes in overflow check
Browse files Browse the repository at this point in the history
  • Loading branch information
radarhere committed Jan 30, 2025
1 parent f6862f7 commit d0b4f70
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions src/_avif.c
Original file line number Diff line number Diff line change
Expand Up @@ -805,7 +805,6 @@ _decoder_get_frame(AvifDecoderObject *self, PyObject *args) {
avifDecoder *decoder;
avifImage *image;
uint32_t frame_index;
uint32_t row_bytes;

decoder = self->decoder;

Expand Down Expand Up @@ -838,13 +837,6 @@ _decoder_get_frame(AvifDecoderObject *self, PyObject *args) {
rgb.ignoreAlpha = AVIF_TRUE;
}

row_bytes = rgb.width * avifRGBImagePixelSize(&rgb);

if (rgb.height > PY_SSIZE_T_MAX / row_bytes) {
PyErr_SetString(PyExc_MemoryError, "Integer overflow in pixel size");
return NULL;
}

result = avifRGBImageAllocatePixels(&rgb);
if (result != AVIF_RESULT_OK) {
PyErr_Format(
Expand All @@ -869,6 +861,11 @@ _decoder_get_frame(AvifDecoderObject *self, PyObject *args) {
return NULL;
}

if (rgb.height > PY_SSIZE_T_MAX / rgb.rowBytes) {
PyErr_SetString(PyExc_MemoryError, "Integer overflow in pixel size");
return NULL;
}

size = rgb.rowBytes * rgb.height;

bytes = PyBytes_FromStringAndSize((char *)rgb.pixels, size);
Expand Down

0 comments on commit d0b4f70

Please sign in to comment.