diff --git a/extmod/moduzlib.c b/extmod/moduzlib.c index b2f5b5af33..4276c366cd 100644 --- a/extmod/moduzlib.c +++ b/extmod/moduzlib.c @@ -175,13 +175,18 @@ STATIC mp_obj_t mod_uzlib_decompress(size_t n_args, const mp_obj_t *args) { decomp->source_limit = (byte *)bufinfo.buf + bufinfo.len; int st; - bool is_zlib = true; + mp_int_t wbits = 0; - if (n_args > 1 && MP_OBJ_SMALL_INT_VALUE(args[1]) < 0) { - is_zlib = false; + if (n_args > 1) { + wbits = MP_OBJ_SMALL_INT_VALUE(args[1]); } - if (is_zlib) { + if (wbits >= 16) { + st = uzlib_gzip_parse_header(decomp); + if (st < 0) { + goto error; + } + } else if (wbits >= 0) { st = uzlib_zlib_parse_header(decomp); if (st < 0) { goto error;