HDFGroup / HDFGroup/hdf5

Heap-buffer-overflow in H5O__mtime_new_decode() in H5Omtime.c

Open
#6,401 3 comments 0 reactions 1 assignee Claimed by @bmribler View on GitHub
Component - C Library Type - Security
Dominant language
C
Stars
988
Forks
355
Avg merge
4d 2h
Merged PRs (30d)
12

Description

**Describe the bug**

A heap buffer overflow occurs in `H5O__mtime_new_decode` when parsing a malformed HDF5 file.

**To Reproduce**
Steps to reproduce the behavior:

1. Clone the hdf5 repository and build it refer to oss-fuzz.

```shell
export CC=clang \
CXX=clang++ \
CFLAGS='-fsanitize=address -O0 -g' \
CXXFLAGS='-fsanitize=address -O0 -g' \
LIB_FUZZING_ENGINE='-fsanitize=fuzzer'
```

2. Run the PoC using h5_extended_fuzzer:

[poc.zip](https://github.com/user-attachments/files/27470497/poc.zip)

The PoC is provided as a zip archive. After extracting, run:

```shell
./h5_extended_fuzzer ./poc
```

**ASAN Report**

```
INFO: Running with entropic power schedule (0xFF, 100).
INFO: Seed: 469515172
./fuzzers/h5_extended_fuzzer: Running 1 inputs 1 time(s) each.
Running: ./crashes/poc
=================================================================
==591009==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x51200003bb57 at pc 0x5e2b67d7d5de bp 0x7ffd220317f0 sp 0x7ffd220317e8
READ of size 4 at 0x51200003bb57 thread T0
#0 0x5e2b67d7d5dd in H5O__mtime_new_decode /home/hexijie/fuzz/project/hdf5/src/H5Omtime.c:137:5
#1 0x5e2b67d289a0 in H5O__chunk_deserialize /home/hexijie/fuzz/project/hdf5/src/H5Ocache.c:1475:35
#2 0x5e2b67d223bc in H5O__cache_deserialize /home/hexijie/fuzz/project/hdf5/src/H5Ocache.c:300:9
#3 0x5e2b67abd47d in H5C__load_entry /home/hexijie/fuzz/project/hdf5/src/H5Centry.c:1241:26
#4 0x5e2b67abd47d in H5C_protect /home/hexijie/fuzz/project/hdf5/src/H5Centry.c:3149:30
#5 0x5e2b67a735bd in H5AC_protect /home/hexijie/fuzz/project/hdf5/src/H5AC.c:1302:26
#6 0x5e2b67d5b4e0 in H5O_protect /home/hexijie/fuzz/project/hdf5/src/H5Oint.c:1012:32
#7 0x5e2b67d75ba2 in H5O_msg_exists /home/hexijie/fuzz/project/hdf5/src/H5Omessage.c:790:23
#8 0x5e2b67c7bcca in H5G_mkroot /home/hexijie/fuzz/project/hdf5/src/H5Groot.c:254:49
#9 0x5e2b67bb11af in H5F_open /home/hexijie/fuzz/project/hdf5/src/H5Fint.c:2140:13
#10 0x5e2b6835bc72 in H5VL__native_file_open /home/hexijie/fuzz/project/hdf5/src/H5VLnative_file.c:127:9
#11 0x5e2b68328bf7 in H5VL__file_open /home/hexijie/fuzz/project/hdf5/src/H5VLcallback.c:3714:25
#12 0x5e2b6832851e in H5VL_file_open /home/hexijie/fuzz/project/hdf5/src/H5VLcallback.c:3832:30
#13 0x5e2b67b959f2 in H5F__open_api_common /home/hexijie/fuzz/project/hdf5/src/H5F.c:780:29
#14 0x5e2b67b95174 in H5Fopen /home/hexijie/fuzz/project/hdf5/src/H5F.c:820:22
#15 0x5e2b67a48b8c in LLVMFuzzerTestOneInput /home/hexijie/fuzz/project/h5_extended_fuzzer.c:29:24
#16 0x5e2b67953f24 in fuzzer::Fuzzer::ExecuteCallback(unsigned char const*, unsigned long) (/home/hexijie/fuzz/fuzzers/h5_extended_fuzzer+0x189f24) (BuildId: 0cb494391ceb010b0af7ad175bb7d4829b45aafc)
#17 0x5e2b6793d056 in fuzzer::RunOneTest(fuzzer::Fuzzer*, char const*, unsigned long) (/home/hexijie/fuzz/fuzzers/h5_extended_fuzzer+0x173056) (BuildId: 0cb494391ceb010b0af7ad175bb7d4829b45aafc)
#18 0x5e2b67942b0a in fuzzer::FuzzerDriver(int*, char***, int (*)(unsigned char const*, unsigned long)) (/home/hexijie/fuzz/fuzzers/h5_extended_fuzzer+0x178b0a) (BuildId: 0cb494391ceb010b0af7ad175bb7d4829b45aafc)
#19 0x5e2b6796d2c6 in main (/home/hexijie/fuzz/fuzzers/h5_extended_fuzzer+0x1a32c6) (BuildId: 0cb494391ceb010b0af7ad175bb7d4829b45aafc)
#20 0x74900c42a1c9 in __libc_start_call_main csu/../sysdeps/nptl/libc_start_call_main.h:58:16
#21 0x74900c42a28a in __libc_start_main csu/../csu/libc-start.c:360:3
#22 0x5e2b67937c24 in _start (/home/hexijie/fuzz/fuzzers/h5_extended_fuzzer+0x16dc24) (BuildId: 0cb494391ceb010b0af7ad175bb7d4829b45aafc)

0x51200003bb57 is located 0 bytes after 279-byte region [0x51200003ba40,0x51200003bb57)
allocated by thread T0 here:
#0 0x5e2b67a08053 in malloc (/home/hexijie/fuzz/fuzzers/h5_extended_fuzzer+0x23e053) (BuildId: 0cb494391ceb010b0af7ad175bb7d4829b45aafc)
#1 0x5e2b67c3d60c in H5FL__malloc /home/hexijie/fuzz/project/hdf5/src/H5FL.c:211:30
#2 0x5e2b67c3d60c in H5FL_blk_malloc /home/hexijie/fuzz/project/hdf5/src/H5FL.c:773:48

SUMMARY: AddressSanitizer: heap-buffer-overflow /home/hexijie/fuzz/project/hdf5/src/H5Omtime.c:137:5 in H5O__mtime_new_decode
Shadow bytes around the buggy address:
0x51200003b880: fa fa fa fa fa fa fa fa 00 00 00 00 00 00 00 00
0x51200003b900: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x51200003b980: 00 00 00 00 00 00 00 00 00 07 fa fa fa fa fa fa
0x51200003ba00: fa fa fa fa fa fa fa fa 00 00 00 00 00 00 00 00
0x51200003ba80: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
=>0x51200003bb00: 00 00 00 00 00 00 00 00 00 00[07]fa fa fa fa fa
0x51200003bb80: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x51200003bc00: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x51200003bc80: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x51200003bd00: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x51200003bd80: 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
==591009==ABORTING
```

**Platform:**

- OS: Ubuntu 22.04 (x86_64)
- Version: commit 877fb52e33bbb7cba685cd38377a7f2c83e5c0c1

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.