Project: exiv2 (exiv2/exiv2), language: c++
Vulnerability instance: exiv2.cve-2018-10999
Sanitizer: address

================= Bug Report (1/1) ==================
## Source: GitHub Issue
## URL: https://github.com/Exiv2/exiv2/issues/306
## Description:
Issue: Exiv2/exiv2#306
Title: heap-buffer-overflow on Exiv2::Internal::PngChunk::parseTXTChunk
State: closed
Created by: legend-issue
Created at: 2018-05-10 09:43:16+00:00

Issue Body:
```jsx
=================================================================
==30669==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x61a00001f710 at pc 0x7fa47d77b20b bp 0x7ffd844044b0 sp 0x7ffd84403c58
READ of size 1137 at 0x61a00001f710 thread T0
    #0 0x7fa47d77b20a in __interceptor_strlen (/usr/lib/x86_64-linux-gnu/libasan.so.2+0x7020a)
    #1 0x7fa47d3ce8bf in Exiv2::Internal::PngChunk::parseTXTChunk(Exiv2::DataBuf const&, int, Exiv2::Internal::PngChunk::TxtChunkType) (/home/aflgo/song/exiv2/src/.libs/libexiv2.so.26+0x19a8bf)
    #2 0x7fa47d3ced0a in Exiv2::Internal::PngChunk::decodeTXTChunk(Exiv2::Image*, Exiv2::DataBuf const&, Exiv2::Internal::PngChunk::TxtChunkType) (/home/aflgo/song/exiv2/src/.libs/libexiv2.so.26+0x19ad0a)
    #3 0x7fa47d3cb061 in Exiv2::PngImage::readMetadata() (/home/aflgo/song/exiv2/src/.libs/libexiv2.so.26+0x197061)
    #4 0x419978 in Action::Extract::writeThumbnail() const (/home/aflgo/song/exiv2/bin/.libs/lt-exiv2+0x419978)
    #5 0x422327 in Action::Extract::run(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) (/home/aflgo/song/exiv2/bin/.libs/lt-exiv2+0x422327)
    #6 0x406dbd in main (/home/aflgo/song/exiv2/bin/.libs/lt-exiv2+0x406dbd)
    #7 0x7fa47c8f282f in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2082f)
    #8 0x407098 in _start (/home/aflgo/song/exiv2/bin/.libs/lt-exiv2+0x407098)

0x61a00001f710 is located 0 bytes to the right of 1168-byte region [0x61a00001f280,0x61a00001f710)
allocated by thread T0 here:
    #0 0x7fa47d7a46b2 in operator new[](unsigned long) (/usr/lib/x86_64-linux-gnu/libasan.so.2+0x996b2)
    #1 0x7fa47d3cae67 in Exiv2::PngImage::readMetadata() (/home/aflgo/song/exiv2/src/.libs/libexiv2.so.26+0x196e67)

SUMMARY: AddressSanitizer: heap-buffer-overflow ??:0 __interceptor_strlen
Shadow bytes around the buggy address:
  0x0c347fffbe90: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0c347fffbea0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0c347fffbeb0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0c347fffbec0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0c347fffbed0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
=>0x0c347fffbee0: 00 00[fa]fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c347fffbef0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c347fffbf00: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c347fffbf10: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c347fffbf20: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c347fffbf30: 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
==30669==ABORTING
```

command: exiv2 -et [poc]
https://github.com/legend-issue/pocs/blob/master/exiv2/id:000004%2Csig:06%2Csrc:000036%2Cop:havoc%2Crep:128


Comments:
Comment by fgeek on 2018-05-15 01:34:40+00:00:
Probably duplicate of #302.

---

Comment by fgeek on 2018-05-15 06:59:44+00:00:
CVE-2018-10999 has been assigned for this issue (not requested by me).

---

Comment by piponazo on 2018-05-19 10:41:33+00:00:
I could reproduce the issue with the Address sanitizer. I will investigate the issue and try to fix it.

---

Comment by fgeek on 2018-05-19 15:14:43+00:00:
Great :) :+1: 

---

Comment by piponazo on 2018-05-23 08:58:21+00:00:
The bug should be fixed now. Thanks for the report. 

Build script:
#!/bin/bash -eu
# Minimized build script with only core build commands
set -eu
mkdir -p build
cd build
cmake -DEXIV2_ENABLE_PNG=ON -DEXIV2_ENABLE_WEBREADY=ON -DEXIV2_ENABLE_CURL=OFF -DEXIV2_ENABLE_BMFF=ON -DEXIV2_TEAM_WARNINGS_AS_ERRORS=ON -DBUILD_SHARED_LIBS=OFF -DCMAKE_CXX_COMPILER="${CXX}" -DCMAKE_CXX_FLAGS="${CXXFLAGS}" -DEXIV2_BUILD_FUZZ_TESTS=ON -DEXIV2_TEAM_OSS_FUZZ=ON -DLIB_FUZZING_ENGINE="${LIB_FUZZING_ENGINE}" ..
make -j $(nproc)

Dockerfile:
FROM hwiwonlee/secb.base:latest
RUN apt-get update && apt-get install -y cmake make ccache python3 libexpat1-dev zlib1g-dev libssh-dev libcurl4-openssl-dev libxml2-utils
RUN git clone https://github.com/exiv2/exiv2 exiv2
RUN git -C exiv2 checkout fa449a4d2c58d63f0d75ff259f25683a98a44630
WORKDIR $SRC/exiv2
COPY build.sh $SRC/

Additional files: