diff --git a/gen/c/std/gif.c b/gen/c/std/gif.c index 05ab5ff0..21170eba 100644 --- a/gen/c/std/gif.c +++ b/gen/c/std/gif.c @@ -83,9 +83,10 @@ typedef enum { puffs_gif_error_bad_gif_block = -256 + 1, puffs_gif_error_bad_gif_extension_label = -258 + 1, puffs_gif_error_bad_gif_header = -260 + 1, - puffs_gif_error_todo_unsupported_local_color_table = -262 + 1, - puffs_gif_error_lzw_code_is_out_of_range = -264 + 1, - puffs_gif_error_lzw_prefix_chain_is_cyclical = -266 + 1, + puffs_gif_error_bad_lzw_literal_width = -262 + 1, + puffs_gif_error_todo_unsupported_local_color_table = -264 + 1, + puffs_gif_error_lzw_code_is_out_of_range = -266 + 1, + puffs_gif_error_lzw_prefix_chain_is_cyclical = -268 + 1, } puffs_gif_status; bool puffs_gif_status_is_error(puffs_gif_status s); @@ -189,7 +190,7 @@ bool puffs_gif_status_is_error(puffs_gif_status s) { return s & 1; } -const char* puffs_gif_status_strings[15] = { +const char* puffs_gif_status_strings[16] = { "gif: ok", "gif: bad version", "gif: bad receiver", @@ -202,6 +203,7 @@ const char* puffs_gif_status_strings[15] = { "gif: bad GIF block", "gif: bad GIF extension label", "gif: bad GIF header", + "gif: bad LZW literal width", "gif: TODO: unsupported Local Color Table", "gif: LZW code is out of range", "gif: LZW prefix chain is cyclical", @@ -214,7 +216,7 @@ const char* puffs_gif_status_string(puffs_gif_status s) { return puffs_gif_status_strings[s]; } s -= 119; - if ((9 <= s) && (s < 15)) { + if ((9 <= s) && (s < 16)) { return puffs_gif_status_strings[s]; } } @@ -532,7 +534,9 @@ puffs_gif_status puffs_gif_decoder_decode_id(puffs_gif_decoder* self, } uint8_t t_1 = a_src.buf->ptr[a_src.buf->ri++]; v_literal_width = t_1; - v_literal_width *= 0; + if ((v_literal_width < 2) || (8 < v_literal_width)) { + return puffs_gif_error_bad_lzw_literal_width; + } while (true) { if (a_src.buf->ri >= a_src.buf->wi) { status = a_src.buf->closed ? puffs_gif_error_unexpected_eof diff --git a/gen/h/std/gif.h b/gen/h/std/gif.h index 61eab19c..a10ca90d 100644 --- a/gen/h/std/gif.h +++ b/gen/h/std/gif.h @@ -83,9 +83,10 @@ typedef enum { puffs_gif_error_bad_gif_block = -256 + 1, puffs_gif_error_bad_gif_extension_label = -258 + 1, puffs_gif_error_bad_gif_header = -260 + 1, - puffs_gif_error_todo_unsupported_local_color_table = -262 + 1, - puffs_gif_error_lzw_code_is_out_of_range = -264 + 1, - puffs_gif_error_lzw_prefix_chain_is_cyclical = -266 + 1, + puffs_gif_error_bad_lzw_literal_width = -262 + 1, + puffs_gif_error_todo_unsupported_local_color_table = -264 + 1, + puffs_gif_error_lzw_code_is_out_of_range = -266 + 1, + puffs_gif_error_lzw_prefix_chain_is_cyclical = -268 + 1, } puffs_gif_status; bool puffs_gif_status_is_error(puffs_gif_status s); diff --git a/lang/check/bounds.go b/lang/check/bounds.go index 152098af..e93b82c0 100644 --- a/lang/check/bounds.go +++ b/lang/check/bounds.go @@ -117,8 +117,22 @@ func invert(tm *t.Map, n *a.Expr) (*a.Expr, error) { id0 = t.IDXBinaryLessThan case t.KeyXBinaryGreaterThan: id0 = t.IDXBinaryLessEq + case t.KeyXBinaryAnd, t.KeyXBinaryOr: + var err error + lhs, err = invert(tm, lhs) + if err != nil { + return nil, err + } + rhs, err = invert(tm, rhs) + if err != nil { + return nil, err + } + if id0.Key() == t.KeyXBinaryAnd { + id0 = t.IDXBinaryOr + } else { + id0 = t.IDXBinaryAnd + } default: - // TODO: De Morgan's law for t.IDXBinaryAnd, t.IDXBinaryOr? id0, lhs, rhs = t.IDXUnaryNot, nil, n } o := a.NewExpr(n.Node().Raw().Flags(), id0, 0, lhs.Node(), nil, rhs.Node(), nil) diff --git a/std/gif/decode_gif.puffs b/std/gif/decode_gif.puffs index 6baaf679..f4870940 100644 --- a/std/gif/decode_gif.puffs +++ b/std/gif/decode_gif.puffs @@ -6,6 +6,7 @@ pub error "bad GIF block" pub error "bad GIF extension label" pub error "bad GIF header" +pub error "bad LZW literal width" pub error "TODO: unsupported Local Color Table" @@ -138,7 +139,9 @@ pri func decoder.decode_id?(src reader1)() { var literal_width u8 = in.src.read_u8?() // TODO: call this.lzw.set_literal_width. - literal_width *= 0 // Avoid "unused variable" C compiler warning. + if (literal_width < 2) or (8 < literal_width) { + return error "bad LZW literal width" + } // TODO: pass the data blocks' payload to this.lzw. while true {