Skip to content
Myr

Fix leak on too-large programs, OSS Fuzz issue 61349

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

A very large program can cause these leaks: ==758838== 7,820 (16 direct, 7,804 indirect) bytes in 2 blocks are definitely lost in loss record 17 of 28 ==758838== at 0x4848A23: calloc (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so) ==758838== by 0x125D30: jv_mem_calloc (jv_alloc.c:153) ==758838== by 0x162ADE: compile (compile.c:1286) ==758838== by 0x162D4B: compile (compile.c:1304) ==758838== by 0x163697: block_compile (compile.c:1381) ==758838== by 0x11B5CA: jq_compile_args (execute.c:1245) ==758838== by 0x115E20: main (main.c:691) ==758838== ==758838== 1,674,694 (103,576 direct, 1,571,118 indirect) bytes in 1,177 blocks are definitely lost in loss record 28 of 28 ==758838== at 0x4843839: malloc (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so) ==758838== by 0x125CD0: jv_mem_alloc (jv_alloc.c:141) ==758838== by 0x162B19: compile (compile.c:1289) ==758838== by 0x163697: block_compile (compile.c:1381) ==758838== by 0x11B5CA: jq_compile_args (execute.c:1245) ==758838== by 0x115E20: main (main.c:691) This commit fixes that. Fixes https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=61349

authored by Nico Williams · committed by GitHub · parent 91d7257 · Browse files · 1 file+2 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+2 added−1 removed

  • other:+2 added−1 removed

1 file+2 added−1 removed

modified:src/compile.c+2 added-1 removed
1280 unmodified lines
1281 errors++;1282 }1283 bc->codelen = pos;1284 bc->debuginfo = jv_object_set(bc->debuginfo, jv_string("locals"), localnames);1285 if (bc->nsubfunctions) {1285 if (bc->nsubfunctions && !errors) {1286 bc->subfunctions = jv_mem_calloc(sizeof(struct bytecode*), bc->nsubfunctions);1287 for (inst* curr = b.first; curr; curr = curr->next) {1288 if (curr->op == CLOSURE_CREATE) {1289 struct bytecode* subfn = jv_mem_alloc(sizeof(struct bytecode));
15 unmodified lines
1305 curr->subfn = gen_noop();1306 }1307 }1308 } else {1309 bc->nsubfunctions = 0;1310 bc->subfunctions = 0;1311 }1312 uint16_t* code = jv_mem_calloc(sizeof(uint16_t), bc->codelen);1313 bc->code = code;
88 unmodified lines