Skip to content

rz-find: don't truncate strings in -Z mode - #6761

Closed
kisnner26 wants to merge 1 commit into
rizinorg:devfrom
kisnner26:fix-rzfind-Z-truncation
Closed

kisnner26 wants to merge 1 commit into
rizinorg:devfrom
kisnner26:fix-rzfind-Z-truncation

Conversation

@kisnner26

Copy link
Copy Markdown

fixes #6289

hit() copies each matched string into a fixed 128-byte stack buffer (char _str[128]), so rz-find -Z cuts off any string longer than 127 characters. That's exactly what the issue shows: C++ mangled symbol names from LIEF (_ZN4LIEF7Android16ANDROID_VERSION...) get chopped mid-identifier, while the same strings print in full through izz.

The same loop also reads ro->buf[delta + i] without checking that stays inside the block that was actually read into ro->buf (sized ro->bsize, user-adjustable with -b), so a hit near the end of a block smaller than the string buffer can read past the allocation.

This PR:

  • grows the buffer to 4096 bytes, well past any string rz-find would realistically need to show
  • bounds the copy loop by min(sizeof(buffer)-1, ro->bsize - delta), fixing the truncation and the latent out-of-bounds read in the same change
  • adds a regression test using the exact binary from the issue (bins/elf/0pack in rizin-testbins), asserting the previously-truncated symbol names now print in full and match rz's own izz output for the same strings

verified locally: built with meson/ninja, ran rz-find -s Android -Z bins/elf/0pack before/after — confirmed the 130-char mangled names were truncated on master and print in full with this fix, matching izz exactly. Ran the full test/db/tools/rz_find suite against rizin-testbins; the new test passes and no other test regresses (a handful of pre-existing unrelated tests fail in my local setup due to the magic DB / PATH not being installed system-wide, not from this change).

hit() copied matched strings into a fixed 128-byte stack buffer, so any
string longer than 127 chars printed by rz-find -Z got cut off (issue
rizinorg#6289: a C++ mangled symbol name from LIEF got chopped mid-identifier).
The same fixed-size loop also read ro->buf[delta + i] without checking
it stayed inside the bsize-sized block that was actually read, an
out-of-bounds read for hits near the end of a block smaller than the
buffer.

Grow the buffer to 4096 bytes and bound the copy loop by the number of
bytes actually available in the current block (ro->bsize - delta),
fixing both the truncation and the latent OOB read.

Verified against the exact binary from the issue (bins/elf/0pack in
rizin-testbins): the previously truncated symbol names now print in
full and match rz's own izz output.
@Rot127

Rot127 commented Sep 18, 2026

Copy link
Copy Markdown
Member

It is not allowed to use AI for a good-first-issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

rz-find truncates strings during the -Z mode

2 participants