mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-12-28 19:06:18 +03:00
Refactor to macro
This commit is contained in:
parent
c66d8aa754
commit
f6926a041b
|
@ -24,6 +24,11 @@
|
||||||
#define I32(ptr)\
|
#define I32(ptr)\
|
||||||
((ptr)[0] + ((ptr)[1] << 8) + ((ptr)[2] << 16) + ((ptr)[3] << 24))
|
((ptr)[0] + ((ptr)[1] << 8) + ((ptr)[2] << 16) + ((ptr)[3] << 24))
|
||||||
|
|
||||||
|
#define ERR_IF_DATA_OOB(offset) \
|
||||||
|
if ((data + (offset)) > ptr + bytes) {\
|
||||||
|
state->errcode = IMAGING_CODEC_OVERRUN; \
|
||||||
|
return -1; \
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
ImagingFliDecode(Imaging im, ImagingCodecState state, UINT8* buf, Py_ssize_t bytes)
|
ImagingFliDecode(Imaging im, ImagingCodecState state, UINT8* buf, Py_ssize_t bytes)
|
||||||
|
@ -170,21 +175,15 @@ ImagingFliDecode(Imaging im, ImagingCodecState state, UINT8* buf, Py_ssize_t byt
|
||||||
UINT8* out = (UINT8*) im->image[y];
|
UINT8* out = (UINT8*) im->image[y];
|
||||||
data += 1; /* ignore packetcount byte */
|
data += 1; /* ignore packetcount byte */
|
||||||
for (x = 0; x < state->xsize; x += i) {
|
for (x = 0; x < state->xsize; x += i) {
|
||||||
if (data + 2 > ptr + bytes ) {
|
|
||||||
/* Out of Bounds Read issue, guaranteed to try to read 2 from data */
|
/* Out of Bounds Read issue, guaranteed to try to read 2 from data */
|
||||||
state->errcode = IMAGING_CODEC_OVERRUN;
|
ERR_IF_DATA_OOB(2)
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
if (data[0] & 0x80) {
|
if (data[0] & 0x80) {
|
||||||
i = 256 - data[0];
|
i = 256 - data[0];
|
||||||
if (x + i > state->xsize) {
|
if (x + i > state->xsize) {
|
||||||
break; /* safety first */
|
break; /* safety first */
|
||||||
}
|
}
|
||||||
if (data + i + 1 > ptr + bytes ) {
|
/* Out of Bounds read issue */
|
||||||
/* Out of Bounds Read issue */
|
ERR_IF_DATA_OOB(i+1)
|
||||||
state->errcode = IMAGING_CODEC_OVERRUN;
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
memcpy(out + x, data + 1, i);
|
memcpy(out + x, data + 1, i);
|
||||||
data += i + 1;
|
data += i + 1;
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user