Skip to content

Fix fast parser small-buffer padding#608

Open
ahtcx wants to merge 1 commit into
liquidaty:mainfrom
ahtcx:ahtcx/fix-small-buffer-padding
Open

Fix fast parser small-buffer padding#608
ahtcx wants to merge 1 commit into
liquidaty:mainfrom
ahtcx:ahtcx/fix-small-buffer-padding

Conversation

@ahtcx
Copy link
Copy Markdown

@ahtcx ahtcx commented Apr 28, 2026

The v1.4.1 regression described in #603 still happens in v1.4.2 for me. I'm not very familiar with C nor the codebase, so I got AI to write this MR. I hope it's relevant, if not feel free to close the MR. Thanks!

@liquidaty
Copy link
Copy Markdown
Owner

Much appreciated, thank you

@iamazeem
Copy link
Copy Markdown
Collaborator

iamazeem commented Apr 29, 2026

@ahtcx: Are you, by any chance, using ASan for this?
There's no mention of ASan in #603.
What's your compilation command and environment like?

I'm able to reproduce this with ASan with v1.4.2:

=================================================================
==3787669==ERROR: AddressSanitizer: stack-buffer-underflow on address 0x7ffe8fa9cbd2 at pc 0x7fe189cabf01 bp 0x7ffe8fa9cb70 sp 0x7ffe8fa9c318
READ of size 3 at 0x7ffe8fa9cbd2 thread T0
    #0 0x7fe189cabf00 in MemcmpInterceptorCommon(void*, int (*)(void const*, void const*, unsigned long), void const*, void const*, unsigned long) ../../../../src/libsanitizer/sanitizer_common/sanitizer_common_interceptors.inc:860
    #1 0x7fe189cac466 in __interceptor_memcmp ../../../../src/libsanitizer/sanitizer_common/sanitizer_common_interceptors.inc:892
    #2 0x7fe189cac466 in __interceptor_memcmp ../../../../src/libsanitizer/sanitizer_common/sanitizer_common_interceptors.inc:887
    #3 0x5596a7cf9903 in cell_eq /home/azeem/Downloads/zsv-603/zsv-603-repro.c:11
    #4 0x5596a7cf9ebc in on_row /home/azeem/Downloads/zsv-603/zsv-603-repro.c:34
    #5 0x5596a7d013a1 in zsv_finish (/home/azeem/Downloads/zsv-603/zsv-603-repro+0xa3a1)
    #6 0x5596a7cfa2b3 in main /home/azeem/Downloads/zsv-603/zsv-603-repro.c:71
    #7 0x7fe1899fcd8f in __libc_start_call_main ../sysdeps/nptl/libc_start_call_main.h:58
    #8 0x7fe1899fce3f in __libc_start_main_impl ../csu/libc-start.c:392
    #9 0x5596a7cf96f4 in _start (/home/azeem/Downloads/zsv-603/zsv-603-repro+0x26f4)

Address 0x7ffe8fa9cbd2 is located in stack of thread T0 at offset 18 in frame
    #0 0x5596a7cf97c8 in cell_eq /home/azeem/Downloads/zsv-603/zsv-603-repro.c:9

  This frame has 1 object(s):
    [32, 56) 'c' (line 9) <== Memory access at offset 18 underflows this variable
HINT: this may be a false positive if your program uses some custom stack unwind mechanism, swapcontext or vfork
      (longjmp and C++ exceptions *are* supported)
SUMMARY: AddressSanitizer: stack-buffer-underflow ../../../../src/libsanitizer/sanitizer_common/sanitizer_common_interceptors.inc:860 in MemcmpInterceptorCommon(void*, int (*)(void const*, void const*, unsigned long), void const*, void const*, unsigned long)
Shadow bytes around the buggy address:
  0x100051f4b920: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x100051f4b930: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x100051f4b940: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x100051f4b950: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x100051f4b960: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
=>0x100051f4b970: 00 00 00 00 00 00 00 00 f1 f1[f1]f1 00 00 00 f3
  0x100051f4b980: f3 f3 f3 f3 00 00 00 00 00 00 00 00 00 00 00 00
  0x100051f4b990: 00 00 00 00 f1 f1 f1 f1 00 00 00 f3 f3 f3 f3 f3
  0x100051f4b9a0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x100051f4b9b0: 00 00 00 00 00 00 f1 f1 f1 f1 f1 f1 00 00 00 00
  0x100051f4b9c0: 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
==3787669==ABORTING

@ahtcx
Copy link
Copy Markdown
Author

ahtcx commented Apr 29, 2026

@iamazeem No, sorry I should have mentionned before but I'm compiling zsv with the Swift C interopability language features.

@liquidaty
Copy link
Copy Markdown
Owner

I'd like to include a test for this, which should fail (or perhaps seg fault) without this change, and should succeed with this change. @ahtcx any suggestions on the simplest way to come up with that?

@liquidaty liquidaty mentioned this pull request May 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants