tight2: Make sure jpeg isn't too big for buffer

tight-encoder-v2
Andri Yngvason 2020-07-09 13:59:53 +00:00
parent c5be1ecd22
commit 2ddf58593c
1 changed files with 7 additions and 2 deletions

View File

@ -312,14 +312,19 @@ static int tight_encode_tile_jpeg(struct tight_encoder_v2* self,
&size, TJSAMP_422, quality, TJFLAG_FASTDCT); &size, TJSAMP_422, quality, TJFLAG_FASTDCT);
if (rc < 0) { if (rc < 0) {
log_error("Failed to encode tight JPEG box: %s\n", tjGetErrorStr()); log_error("Failed to encode tight JPEG box: %s\n", tjGetErrorStr());
goto compress_failure; goto failure;
}
if (size > MAX_TILE_SIZE) {
log_error("Whoops, encoded JPEG was too big for the buffer\n");
goto failure;
} }
memcpy(tile->buffer, buffer, size); memcpy(tile->buffer, buffer, size);
tile->size = size; tile->size = size;
rc = 0; rc = 0;
compress_failure: failure:
tjDestroy(handle); tjDestroy(handle);
return rc; return rc;