rrthomas / enchant

enchant spellchecking library
http://rrthomas.github.io/enchant/
GNU Lesser General Public License v2.1
347 stars 60 forks source link

ASAN alloc-dealloc-mismatch (operator new [] vs free) warning #384

Closed Girgias closed 6 months ago

Girgias commented 6 months ago

Hello, coming from the PHP project where we have an enchant extension that exposes the C library to PHP.

While running our test suite under ASAN on Fedora 40 I've encountered the following warning:

=================================================================
==952880==ERROR: AddressSanitizer: alloc-dealloc-mismatch (operator new [] vs free) on 0x504000239910
    #0 0x7f3b73cf5558 in free.part.0 (/usr/lib64/../lib64/libasan.so.8+0xf5558) (BuildId: 6ac482fdae6aad7cf603c8e6ab3042fb9d4725af)
    #1 0x7f3b6c12868b in MySpellChecker::suggestWord(char const*, unsigned long, unsigned long*) (/usr/lib64/enchant/libenchant_myspell.so+0x468b) (BuildId: d64f79a0f49e18bc04bbe94868cb01327c40f754)
    #2 0x7f3b732d6032 in enchant_dict_suggest (/usr/lib64/../lib64/libenchant.so.1+0x9032) (BuildId: 4ff518e8612d4659224f482d02b405608dbda234)
    #3 0xe33a70 in zif_enchant_dict_suggest /home/girgias/Dev/php-src/ext/enchant/enchant.c:671
    #4 0x2543f27 in ZEND_DO_ICALL_SPEC_RETVAL_USED_HANDLER /home/girgias/Dev/php-src/Zend/zend_vm_execute.h:1349
    #5 0x27da3e3 in execute_ex /home/girgias/Dev/php-src/Zend/zend_vm_execute.h:57369
    #6 0x27f7923 in zend_execute /home/girgias/Dev/php-src/Zend/zend_vm_execute.h:62776
    #7 0x241f0bc in zend_execute_script /home/girgias/Dev/php-src/Zend/zend.c:1899
    #8 0x219d96d in php_execute_script_ex /home/girgias/Dev/php-src/main/main.c:2507
    #9 0x219de9c in php_execute_script /home/girgias/Dev/php-src/main/main.c:2547
    #10 0x2ba24b1 in do_cli /home/girgias/Dev/php-src/sapi/cli/php_cli.c:966
    #11 0x2ba4c5f in main /home/girgias/Dev/php-src/sapi/cli/php_cli.c:1340
    #12 0x7f3b7023d087 in __libc_start_call_main (/usr/lib64/../lib64/libc.so.6+0x2a087) (BuildId: 4a92fcedbba6d6d2629ce066a2970017faa9995e)
    #13 0x7f3b7023d14a in __libc_start_main_alias_2 (/usr/lib64/../lib64/libc.so.6+0x2a14a) (BuildId: 4a92fcedbba6d6d2629ce066a2970017faa9995e)
    #14 0x60a364 in _start (/home/girgias/Dev/php-src/sapi/cli/php+0x60a364) (BuildId: b11198d44af35ab40ef75c1e5885440a93113dbb)

0x504000239910 is located 0 bytes inside of 40-byte region [0x504000239910,0x504000239938)
allocated by thread T0 here:
    #0 0x7f3b73cf7508 in operator new[](unsigned long) (/usr/lib64/../lib64/libasan.so.8+0xf7508) (BuildId: 6ac482fdae6aad7cf603c8e6ab3042fb9d4725af)
    #1 0x7f3b5c4a90d2 in (anonymous namespace)::munge_vector(char***, std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > const&) (/lib64/libhunspell-1.7.so.0+0x320d2) (BuildId: b122debeae62e7aacb0a7927fda196ebdd79b8ba)
    #2 0x7f3b5c4a959a in HunspellImpl::suggest(char***, char const*) (/lib64/libhunspell-1.7.so.0+0x3259a) (BuildId: b122debeae62e7aacb0a7927fda196ebdd79b8ba)
    #3 0x7f3b6c128544 in MySpellChecker::suggestWord(char const*, unsigned long, unsigned long*) (/usr/lib64/enchant/libenchant_myspell.so+0x4544) (BuildId: d64f79a0f49e18bc04bbe94868cb01327c40f754)
    #4 0x7f3b732d6032 in enchant_dict_suggest (/usr/lib64/../lib64/libenchant.so.1+0x9032) (BuildId: 4ff518e8612d4659224f482d02b405608dbda234)
    #5 0xe33a70 in zif_enchant_dict_suggest /home/girgias/Dev/php-src/ext/enchant/enchant.c:671
    #6 0x2543f27 in ZEND_DO_ICALL_SPEC_RETVAL_USED_HANDLER /home/girgias/Dev/php-src/Zend/zend_vm_execute.h:1349
    #7 0x27da3e3 in execute_ex /home/girgias/Dev/php-src/Zend/zend_vm_execute.h:57369
    #8 0x27f7923 in zend_execute /home/girgias/Dev/php-src/Zend/zend_vm_execute.h:62776
    #9 0x241f0bc in zend_execute_script /home/girgias/Dev/php-src/Zend/zend.c:1899
    #10 0x219d96d in php_execute_script_ex /home/girgias/Dev/php-src/main/main.c:2507
    #11 0x219de9c in php_execute_script /home/girgias/Dev/php-src/main/main.c:2547
    #12 0x2ba24b1 in do_cli /home/girgias/Dev/php-src/sapi/cli/php_cli.c:966
    #13 0x2ba4c5f in main /home/girgias/Dev/php-src/sapi/cli/php_cli.c:1340
    #14 0x7f3b7023d087 in __libc_start_call_main (/usr/lib64/../lib64/libc.so.6+0x2a087) (BuildId: 4a92fcedbba6d6d2629ce066a2970017faa9995e)
    #15 0x7f3b7023d14a in __libc_start_main_alias_2 (/usr/lib64/../lib64/libc.so.6+0x2a14a) (BuildId: 4a92fcedbba6d6d2629ce066a2970017faa9995e)
    #16 0x60a364 in _start (/home/girgias/Dev/php-src/sapi/cli/php+0x60a364) (BuildId: b11198d44af35ab40ef75c1e5885440a93113dbb)

SUMMARY: AddressSanitizer: alloc-dealloc-mismatch (/usr/lib64/../lib64/libasan.so.8+0xf5558) (BuildId: 6ac482fdae6aad7cf603c8e6ab3042fb9d4725af) in free.part.0
==952880==HINT: if you don't care about these errors you may set ASAN_OPTIONS=alloc_dealloc_mismatch=0
==952880==ABORTING

Not exactly sure if the issue is with enchant, or with an underlying provider.

rrthomas commented 6 months ago

This is a very old version of Enchant: I renamed MySpellChecker to HunspellChecker in 2017, in the now-defunct 1.6.x series. Closing.

rrthomas commented 6 months ago

Nice to hear that you're using Enchant, BTW! I hope you manage to update to a newer version.