nfprojects / nfengine

Game engine
GNU General Public License v2.0
56 stars 4 forks source link

Fix errors reported by address sanitizer #164

Closed Witek902 closed 8 years ago

Witek902 commented 8 years ago

First, build project with cmake -DSANITIZE=address .

There is at least one error in ImageTest.cpp:

==17398==ERROR: AddressSanitizer: global-buffer-overflow on address 0x7fb8822fc110 at pc 0x7fb8817b08aa bp 0x7fffd5c5ca30 sp 0x7fffd5c5c1f0
READ of size 384 at 0x7fb8822fc110 thread T0
==17398==WARNING: Trying to symbolize code, but external symbolizer is not initialized!
    #0 0x7fb8817b08a9 (/home/m.witanowski/workspace/nfengine/Bin/x86_64/Debug/nfCommonTest+0x15e8a9)
    #1 0x7fb880eacbc8 (/home/m.witanowski/workspace/nfengine/Bin/x86_64/Debug/libnfCommon.so+0x11dbc8)
    #2 0x7fb8811bcdb9 (/home/m.witanowski/workspace/nfengine/Bin/x86_64/Debug/libnfCommon.so+0x42ddb9)
    #3 0x7fb8811bc623 (/home/m.witanowski/workspace/nfengine/Bin/x86_64/Debug/libnfCommon.so+0x42d623)
    #4 0x7fb88116d94c (/home/m.witanowski/workspace/nfengine/Bin/x86_64/Debug/libnfCommon.so+0x3de94c)
    #5 0x7fb881b8cd83 (/home/m.witanowski/workspace/nfengine/Bin/x86_64/Debug/nfCommonTest+0x53ad83)
    #6 0x7fb881fafc3d (/home/m.witanowski/workspace/nfengine/Bin/x86_64/Debug/nfCommonTest+0x95dc3d)
    #7 0x7fb881fac613 (/home/m.witanowski/workspace/nfengine/Bin/x86_64/Debug/nfCommonTest+0x95a613)
    #8 0x7fb881f9df22 (/home/m.witanowski/workspace/nfengine/Bin/x86_64/Debug/nfCommonTest+0x94bf22)
    #9 0x7fb881f9e6a5 (/home/m.witanowski/workspace/nfengine/Bin/x86_64/Debug/nfCommonTest+0x94c6a5)
    #10 0x7fb881f9eceb (/home/m.witanowski/workspace/nfengine/Bin/x86_64/Debug/nfCommonTest+0x94cceb)
    #11 0x7fb881fa5433 (/home/m.witanowski/workspace/nfengine/Bin/x86_64/Debug/nfCommonTest+0x953433)
    #12 0x7fb881fb09d2 (/home/m.witanowski/workspace/nfengine/Bin/x86_64/Debug/nfCommonTest+0x95e9d2)
    #13 0x7fb881fad2a5 (/home/m.witanowski/workspace/nfengine/Bin/x86_64/Debug/nfCommonTest+0x95b2a5)
    #14 0x7fb881fa41cf (/home/m.witanowski/workspace/nfengine/Bin/x86_64/Debug/nfCommonTest+0x9521cf)
    #15 0x7fb881851640 (/home/m.witanowski/workspace/nfengine/Bin/x86_64/Debug/nfCommonTest+0x1ff640)
    #16 0x7fb8818510a5 (/home/m.witanowski/workspace/nfengine/Bin/x86_64/Debug/nfCommonTest+0x1ff0a5)
    #17 0x7fb87f391ec4 (/lib/x86_64-linux-gnu/libc.so.6+0x21ec4)
    #18 0x7fb8817d687c (/home/m.witanowski/workspace/nfengine/Bin/x86_64/Debug/nfCommonTest+0x18487c)

0x7fb8822fc110 is located 48 bytes to the left of global variable '(anonymous namespace)::TEST_DATA_FORMAT' from '/home/m.witanowski/workspace/nfengine/nfEngine/nfCommonTest/ImageTest.cpp' (0x7fb8822fc140) of size 4
0x7fb8822fc110 is located 0 bytes to the right of global variable '(anonymous namespace)::TEST_DATA' from '/home/m.witanowski/workspace/nfengine/nfEngine/nfCommonTest/ImageTest.cpp' (0x7fb8822fc0e0) of size 48
SUMMARY: AddressSanitizer: global-buffer-overflow ??:0 ??
Shadow bytes around the buggy address:
  0x0ff7904577d0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0ff7904577e0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0ff7904577f0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0ff790457800: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0ff790457810: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
=>0x0ff790457820: 00 00[f9]f9 f9 f9 f9 f9 04 f9 f9 f9 f9 f9 f9 f9
  0x0ff790457830: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0ff790457840: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0ff790457850: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0ff790457860: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0ff790457870: 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
  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
  ASan internal:         fe
==17398==ABORTING
mkulagowski commented 8 years ago

I'm on it.

mkulagowski commented 8 years ago

Image errors reported by sanitizer were produced by libjpeg in decompress function - resulting data array needs to be manually freed. Maybe sometime in the future we will switch to some more up-to-date jpg library like libjpg-turbo, but not yet.

COMMIT IN REVIEW

mkulagowski commented 8 years ago

can be closed