Hello InChI team,
As part of our fuzzing efforts at Google, we have identified an issue affecting
InChI (tested with revision v1.05, January 2017).
To reproduce, we are attaching a Dockerfile which compiles the project with
LLVM, taking advantage of the sanitizers that it offers. More information about
how to use the attached Dockerfile can be found here:
https://docs.docker.com/engine/reference/builder/
Instructions:
unzip artifacts_138688544.zip
docker build --build-arg SANITIZER=address --tag=autofuzz-InChI-138688544 autofuzz_138688544
docker run --entrypoint /fuzzing/repro.sh --cap-add=SYS_PTRACE -v $PWD/autofuzz_138688544/poc-76a8419baf333bdd7b37192c3e037587e4fbbc7b5e9d01992eccb6b4ba5a6b35_min:/tmp/poc autofuzz-InChI-138688544 "" /tmp/poc
docker run --cap-add=SYS_PTRACE -v $PWD/autofuzz_138688544/poc-76a8419baf333bdd7b37192c3e037587e4fbbc7b5e9d01992eccb6b4ba5a6b35_min:/tmp/poc -it autofuzz-InChI-138688544
Alternatively, and depending on the bug, you could use gcc, valgrind or other
instrumentation tools to aid in the investigation. The sanitizer error that we
encountered is here:
running fuzzer...
INFO: Seed: 2804068977
/fuzzing/fuzzer: Running 1 inputs 1 time(s) each.
Running: /tmp/poc-76a8419baf333bdd7b37192c3e037587e4fbbc7b5e9d01992eccb6b4ba5a6b35
=================================================================
==6==ERROR: AddressSanitizer: heap-use-after-free on address 0x7f81ab1b625c at pc 0x000000551b3e bp 0x7fff8d6aeeb0 sp 0x7fff8d6aeea8
READ of size 1 at 0x7f81ab1b625c thread T0
#0 0x551b3d in OrigAtData_CheckAndMakePolymerPhaseShifts /fuzzing/INCHI-1-SRC/INCHI_BASE/src/mol_fmt4.c
#1 0x53185f in GetStructFromINCHIEx /fuzzing/INCHI-1-SRC/INCHI_API/libinchi/src/inchi_dll.c:2490:13
#2 0x530c4e in GetStructFromINCHI /fuzzing/INCHI-1-SRC/INCHI_API/libinchi/src/inchi_dll.c:2626:11
#3 0x4fbd42 in LLVMFuzzerTestOneInput /fuzzing/security-research-pocs/autofuzz/inchi_fuzzer.cc:27:3
#4 0x509fd3 in fuzzer::Fuzzer::ExecuteCallback(unsigned char const*, unsigned long) (/fuzzing/fuzzer+0x509fd3)
#5 0x4fc603 in fuzzer::RunOneTest(fuzzer::Fuzzer*, char const*, unsigned long) (/fuzzing/fuzzer+0x4fc603)
#6 0x500ae2 in fuzzer::FuzzerDriver(int*, char***, int (*)(unsigned char const*, unsigned long)) (/fuzzing/fuzzer+0x500ae2)
#7 0x4fc31b in main (/fuzzing/fuzzer+0x4fc31b)
#8 0x7f81ae9d809a in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2409a)
#9 0x421b19 in _start (/fuzzing/fuzzer+0x421b19)
0x7f81ab1b625c is located 92764 bytes inside of 262144-byte region [0x7f81ab19f800,0x7f81ab1df800)
freed by thread T0 here:
#0 0x4c95e2 in free (/fuzzing/fuzzer+0x4c95e2)
#1 0x5d7efa in inchi_strbuf_close /fuzzing/INCHI-1-SRC/INCHI_BASE/src/ichi_io.c:1170:22
#2 0x73edde in MakeInChIOutOfStrFromINChI2 /fuzzing/INCHI-1-SRC/INCHI_BASE/src/ichirvr1.c:5793:5
#3 0x70b4d1 in OneInChI2Atom /fuzzing/INCHI-1-SRC/INCHI_BASE/src/ichirvr4.c:2882:15
#4 0x6a7d30 in InChI2Atom /fuzzing/INCHI-1-SRC/INCHI_BASE/src/ichirvr7.c:161:11
#5 0x6aa97f in AllInchiToStructure /fuzzing/INCHI-1-SRC/INCHI_BASE/src/ichirvr7.c:887:23
#6 0x6882ac in ConvertInChI2Struct /fuzzing/INCHI-1-SRC/INCHI_BASE/src/ichiread.c:9072:11
#7 0x67c3d3 in ReadWriteInChI /fuzzing/INCHI-1-SRC/INCHI_BASE/src/ichiread.c:1055:23
#8 0x5317f1 in GetStructFromINCHIEx /fuzzing/INCHI-1-SRC/INCHI_API/libinchi/src/inchi_dll.c:2481:16
#9 0x530c4e in GetStructFromINCHI /fuzzing/INCHI-1-SRC/INCHI_API/libinchi/src/inchi_dll.c:2626:11
#10 0x4fbd42 in LLVMFuzzerTestOneInput /fuzzing/security-research-pocs/autofuzz/inchi_fuzzer.cc:27:3
#11 0x509fd3 in fuzzer::Fuzzer::ExecuteCallback(unsigned char const*, unsigned long) (/fuzzing/fuzzer+0x509fd3)
previously allocated by thread T0 here:
#0 0x4c9b5a in calloc (/fuzzing/fuzzer+0x4c9b5a)
#1 0x5d7d89 in inchi_strbuf_init /fuzzing/INCHI-1-SRC/INCHI_BASE/src/ichi_io.c:1143:24
#2 0x73e6df in MakeInChIOutOfStrFromINChI2 /fuzzing/INCHI-1-SRC/INCHI_BASE/src/ichirvr1.c:5629:13
#3 0x70b4d1 in OneInChI2Atom /fuzzing/INCHI-1-SRC/INCHI_BASE/src/ichirvr4.c:2882:15
#4 0x6a7d30 in InChI2Atom /fuzzing/INCHI-1-SRC/INCHI_BASE/src/ichirvr7.c:161:11
#5 0x6aa97f in AllInchiToStructure /fuzzing/INCHI-1-SRC/INCHI_BASE/src/ichirvr7.c:887:23
#6 0x6882ac in ConvertInChI2Struct /fuzzing/INCHI-1-SRC/INCHI_BASE/src/ichiread.c:9072:11
#7 0x67c3d3 in ReadWriteInChI /fuzzing/INCHI-1-SRC/INCHI_BASE/src/ichiread.c:1055:23
#8 0x5317f1 in GetStructFromINCHIEx /fuzzing/INCHI-1-SRC/INCHI_API/libinchi/src/inchi_dll.c:2481:16
#9 0x530c4e in GetStructFromINCHI /fuzzing/INCHI-1-SRC/INCHI_API/libinchi/src/inchi_dll.c:2626:11
#10 0x4fbd42 in LLVMFuzzerTestOneInput /fuzzing/security-research-pocs/autofuzz/inchi_fuzzer.cc:27:3
#11 0x509fd3 in fuzzer::Fuzzer::ExecuteCallback(unsigned char const*, unsigned long) (/fuzzing/fuzzer+0x509fd3)
SUMMARY: AddressSanitizer: heap-use-after-free /fuzzing/INCHI-1-SRC/INCHI_BASE/src/mol_fmt4.c in OrigAtData_CheckAndMakePolymerPhaseShifts
Shadow bytes around the buggy address:
0x0ff0b562ebf0: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
0x0ff0b562ec00: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
0x0ff0b562ec10: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
0x0ff0b562ec20: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
0x0ff0b562ec30: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
=>0x0ff0b562ec40: fd fd fd fd fd fd fd fd fd fd fd[fd]fd fd fd fd
0x0ff0b562ec50: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
0x0ff0b562ec60: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
0x0ff0b562ec70: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
0x0ff0b562ec80: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
0x0ff0b562ec90: 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
Shadow gap: cc
==6==ABORTING
We will gladly work with you so you can successfully confirm and reproduce this
issue. Do let us know if you have any feedback surrounding the documentation.
Once you have reproduced the issue, we'd appreciate to learn your expected
timeline for an update to be released. With any fix, please attribute the report
to "Google Autofuzz project".
We are also pleased to inform you that your project is eligible for inclusion to
the OSS-Fuzz project, which can provide additional continuous fuzzing, and
encourage you to investigate integration options.
Don't hesitate to let us know if you have any questions!
Google AutoFuzz Team