Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

retdec-fileinfo reads invalid memory in PeLib::CoffSymbolTable::read() #840

Closed
s3rvac opened this issue Aug 14, 2020 · 1 comment · Fixed by #841
Closed

retdec-fileinfo reads invalid memory in PeLib::CoffSymbolTable::read() #840

s3rvac opened this issue Aug 14, 2020 · 1 comment · Fixed by #841

Comments

@s3rvac
Copy link
Member

s3rvac commented Aug 14, 2020

retdec-fileinfo reads invalid memory in PeLib::CoffSymbolTable::read().

Steps to reproduce

$ retdec-fileinfo FILE

where FILE is C658C0CF5E05A1DDBC91CF0E6FCFCDB0942D1584D113FB594BF5F8EE02F43E4A (the file has 14 MB, so it is unsuitable for adding into our regression-tests suite).

Expected output

Here is the result from retdec-fileinfo before the changes concerning image loading:

Input file               : C658C0CF5E05A1DDBC91CF0E6FCFCDB0942D1584D113FB594BF5F8EE02F43E4A.dat
CRC32                    : 36e6f7c8
MD5                      : 18681bc3fa35570e5099f2fe3b65a958
SHA256                   : c658c0cf5e05a1ddbc91cf0e6fcfcdb0942d1584d113fb594bf5f8ee02f43e4a
File format              : PE
File class               : 32-bit
File type                : Executable file
Loader error             : The file is an in-memory image
Loadable anyway          : No
Architecture             : x86
Endianness               : Little endian
Image base address       : 0x400000
Entry point address      : 0x4014e0
Entry point offset       : 0x8e0
Entry point section name : .text
Entry point section index: 0
Bytes on entry point     : 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
Detected tool            : Microsoft (linker), dos header style
Overlay offset           : 0xc9d004
Overlay size             : 0x97ffc
Overlay entropy          : 4.635

Actual output

retdec-fileinfo crashes:

Segmentation fault

Stacktrace from valgrind

Invalid read of size 1
   at 0x70F6CA: PeLib::CoffSymbolTable::read(PeLib::InputBuffer&, unsigned int) (CoffSymbolTable.cpp:43)
   by 0x70FAFA: PeLib::CoffSymbolTable::read(std::vector<unsigned char, std::allocator<unsigned char> >&, unsigned long, unsigned long) (CoffSymbolTable.cpp:125)
   by 0x721BDD: PeLib::PeFileT::readCoffSymbolTable(std::vector<unsigned char, std::allocator<unsigned char> >&) (PeFile.cpp:280)
   by 0x586ABF: retdec::fileformat::PeFormat::initStructures(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) (pe_format.cpp:883)
   by 0x585FE8: retdec::fileformat::PeFormat::PeFormat(...) (pe_format.cpp:808)
   by 0x4EB4EF: retdec::fileinfo::PeWrapper::PeWrapper(...) (pe_wrapper.cpp:101)
   by 0x45BC42: void __gnu_cxx::new_allocator<...>::construct<...>(...) (new_allocator.h:147)
   by 0x45BB0B: void std::allocator_traits<...>::construct<...>(...) (alloc_traits.h:484)
   by 0x45B94B: std::_Sp_counted_ptr_inplace<...>::_Sp_counted_ptr_inplace<...>(...) (shared_ptr_base.h:548)
   by 0x45B69C: std::__shared_count<...>(...)
   by 0x45B53B: std::__shared_ptr<...>(...)
   by 0x45B3FA: std::shared_ptr<retdec::fileinfo::PeWrapper>::shared_ptr<...>(...)

My configuration

  • Current master (commit 4cf40b4)
  • 64b Debian, GCC 9.2, Debug build
@ladislav-zezula
Copy link
Contributor

#841

s3rvac pushed a commit that referenced this issue Aug 15, 2020
Fixes #840.

Co-authored-by: Ladislav Zezula <ladislav.zezula@avast.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants