Skip to content
Myr

@base64d: fix unhandled overflow

Before adoption: this commit came in with the history the project adopted, so no landing records it.

$ ./jq-before -n '238609295*"|||"|@base64d|"."' src/builtin.c:718:29: runtime error: signed integer overflow: 715827885 * 3 cannot be represented in type 'int' jq: error: cannot allocate memory Aborted (core dumped) $ ./jq-after -n '238609295*"|||"|@base64d|"."' jq: error (at <unknown>): string ("||||||||||...) is not valid base64 data Fixes https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=67640

authored by Emanuele Torre · committed by GitHub · parent be437ec · Browse files · 1 file+1 added−1 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+1 added−1 removed

  • other:+1 added−1 removed

1 file+1 added−1 removed

modified:src/builtin.c+1 added-1 removed
713 unmodified lines
714 jv_free(fmt);715 input = f_tostring(jq, input);716 const unsigned char* data = (const unsigned char*)jv_string_value(input);717 int len = jv_string_length_bytes(jv_copy(input));718 size_t decoded_len = (3 * len) / 4; // 3 usable bytes for every 4 bytes of input718 size_t decoded_len = (3 * (size_t)len) / 4; // 3 usable bytes for every 4 bytes of input719 char *result = jv_mem_calloc(decoded_len, sizeof(char));720 memset(result, 0, decoded_len * sizeof(char));721 uint32_t ri = 0;722 int input_bytes_read=0;
1179 unmodified lines