Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix gzip Decompression Support #8335

Merged
merged 2 commits into from
Aug 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions extmod/moduzlib.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 4 additions & 4 deletions shared-bindings/zlib/__init__.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,12 @@
//| ...
//|
STATIC mp_obj_t zlib_decompress(size_t n_args, const mp_obj_t *args) {
bool is_zlib = true;
if (n_args > 1 && MP_OBJ_SMALL_INT_VALUE(args[1]) < 0) {
is_zlib = false;
mp_int_t wbits = 0;
if (n_args > 1) {
wbits = MP_OBJ_SMALL_INT_VALUE(args[1]);
}

return common_hal_zlib_decompress(args[0], is_zlib);
return common_hal_zlib_decompress(args[0], wbits);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(zlib_decompress_obj, 1, 3, zlib_decompress);

Expand Down
2 changes: 1 addition & 1 deletion shared-bindings/zlib/__init__.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@
#ifndef MICROPY_INCLUDED_SHARED_BINDINGS_ZLIB___INIT___H
#define MICROPY_INCLUDED_SHARED_BINDINGS_ZLIB___INIT___H

mp_obj_t common_hal_zlib_decompress(mp_obj_t data, bool is_zlib);
mp_obj_t common_hal_zlib_decompress(mp_obj_t data, mp_int_t wbits);

#endif // MICROPY_INCLUDED_SHARED_BINDINGS_ZLIB___INIT___H
9 changes: 7 additions & 2 deletions shared-module/zlib/__init__.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
#define DEBUG_printf(...) (void)0
#endif

mp_obj_t common_hal_zlib_decompress(mp_obj_t data, bool is_zlib) {
mp_obj_t common_hal_zlib_decompress(mp_obj_t data, mp_int_t wbits) {
mp_buffer_info_t bufinfo;
mp_get_buffer_raise(data, &bufinfo, MP_BUFFER_READ);

Expand All @@ -66,7 +66,12 @@ mp_obj_t common_hal_zlib_decompress(mp_obj_t data, bool is_zlib) {
decomp->source_limit = (unsigned char *)bufinfo.buf + bufinfo.len;
int st;

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;
Expand Down