Reject bad LZW widths when skipping GIF frames

This commit is contained in:
Nigel Tao committed 2019-05-25 10:56:46 +10:00
1 parent 155e2ff426
commit 74a591ab2b
2 files changed
+21 -7

No files matched your search

+13 -5
View File
@@ -9228,6 +9228,7 @@ wuffs_gif__decoder__skip_frame(wuffs_gif__decoder* self,
wuffs_base__status status = NULL;
uint8_t v_flags = 0;
uint8_t v_lw = 0;
uint8_t* iop_a_src = NULL;
uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
@@ -9273,12 +9274,19 @@ wuffs_gif__decoder__skip_frame(wuffs_gif__decoder* self,
}
iop_a_src += self->private_data.s_skip_frame[0].scratch;
}
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(3);
if (WUFFS_BASE__UNLIKELY(iop_a_src == io1_a_src)) {
status = wuffs_base__suspension__short_read;
goto suspend;
{
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(3);
if (WUFFS_BASE__UNLIKELY(iop_a_src == io1_a_src)) {
status = wuffs_base__suspension__short_read;
goto suspend;
}
uint8_t t_1 = *iop_a_src++;
v_lw = t_1;
}
if ((v_lw < 1) || (8 < v_lw)) {
status = wuffs_gif__error__bad_literal_width;
goto exit;
}
iop_a_src++;
if (a_src.private_impl.buf) {
a_src.private_impl.buf->meta.ri =
((size_t)(iop_a_src - a_src.private_impl.buf->data.ptr));
+8 -2
View File
@@ -392,14 +392,20 @@ pub func decoder.decode_frame_config?(dst nptr base.frame_config, src base.io_re
pri func decoder.skip_frame?(src base.io_reader) {
var flags base.u8
var lw base.u8
// Skip the optional Local Color Table, 3 bytes (RGB) per entry.
flags = args.src.read_u8?()
if (flags & 0x80) <> 0 {
args.src.skip?(n:(3 as base.u32) << (1 + (flags & 0x07)))
}
// Skip the literal width.
args.src.skip?(n:1)
// Process the LZW literal width.
lw = args.src.read_u8?()
if (lw < 1) or (8 < lw) {
return "#bad literal width"
}
// Skip the blocks of LZW-compressed data.
this.skip_blocks?(src:args.src)