Memory errors in buildmaster
Created by: Zaharid
A student has found the following error when working with buildmaser
-- Reading COMMONDATA for Dataset: DYE906R
nData: 6 nSys: 7
buildmaster(70480,0x111d47dc0) malloc: Incorrect checksum for freed object 0x7fb32235d160: probably modified after being freed.
Corrupt value: 0x0
buildmaster(70480,0x111d47dc0) malloc: *** set a breakpoint in malloc_error_break to debug
zsh: abort ./buildmaster
(nnpdf-dev) manuelmorales@dhcp-172-24-140-93 buildmaster %
which I have not reproduced so far. However I have compiled it with address sanitizer by adding
$ git --no-pager diff (base)
diff --git a/buildmaster/CMakeLists.txt b/buildmaster/CMakeLists.txt
index a7516e6c9..08f079c65 100644
--- a/buildmaster/CMakeLists.txt
+++ b/buildmaster/CMakeLists.txt
@@ -45,6 +45,7 @@ pkg_search_module(LHAPDF REQUIRED lhapdf)
pkg_search_module(LIBARCHIVE REQUIRED libarchive)
set(DEFAULT_CXX_OPTIONS "-Wall -Wextra -march=nocona -mtune=haswell \
+ -fsanitize=address \
-fvisibility-inlines-hidden -fmessage-length=0 \
-ftree-vectorize -fPIC -fstack-protector-strong \
-O2 -pipe")
and compiled it in debug mode
$ cmake .. -DCMAKE_BUILD_TYPE=Debug
When I run it I get
=================================================================
==28328==ERROR: AddressSanitizer: dynamic-stack-buffer-overflow on address 0x7ffd5ca1a0c8 at pc 0x56212518d9c0 bp 0x7ffd5ca1a030 sp 0x7ffd5ca1a028
READ of size 8 at 0x7ffd5ca1a0c8 thread T0
#0 0x56212518d9bf in ATLASLOMASSDY11Filter::ReadData() /home/zah/nngit/nnpdf/buildmaster/filters/ATLASLOMASSDY11.cc:85
#1 0x56212511981a in ATLASLOMASSDY11Filter::ATLASLOMASSDY11Filter() /home/zah/nngit/nnpdf/buildmaster/inc/ATLASLOMASSDY11.h:17
#2 0x56212511981a in InitCommonData(std::vector<Buildmaster::CommonData*, std::allocator<Buildmaster::CommonData*> >&) /home/zah/nngit/nnpdf/buildmaster/inc/ATLASLOMASSDY11.h:16
#3 0x562125112399 in main /home/zah/nngit/nnpdf/buildmaster/src/buildmaster.cc:131
#4 0x7f423f0690b2 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x270b2)
#5 0x562125116d4d in _start (/home/zah/nngit/nnpdf/buildmaster/buildmaster+0x179d4d)
Address 0x7ffd5ca1a0c8 is located in stack of thread T0
SUMMARY: AddressSanitizer: dynamic-stack-buffer-overflow /home/zah/nngit/nnpdf/buildmaster/filters/ATLASLOMASSDY11.cc:85 in ATLASLOMASSDY11Filter::ReadData()
Shadow bytes around the buggy address:
0x10002b93b3c0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x10002b93b3d0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x10002b93b3e0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x10002b93b3f0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x10002b93b400: 00 00 00 00 00 00 00 00 ca ca ca ca 00 00 00 00
=>0x10002b93b410: 00 00 00 00 00 00 00 00 00[cb]cb cb cb cb cb cb
0x10002b93b420: 00 00 00 00 ca ca ca ca 00 00 00 00 00 00 00 00
0x10002b93b430: 00 cb cb cb cb cb cb cb 00 00 00 00 00 00 00 00
0x10002b93b440: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x10002b93b450: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x10002b93b460: 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
==28328==ABORTING
Which looks bad.
This needs to run without errors and we have to check if some result changes.