Skip to content

core: Fix ps command truncating strings longer than 256 bytes#5997

Open
cheese-cakee wants to merge 6 commits intorizinorg:devfrom
cheese-cakee:fix-ps-long-strings
Open

core: Fix ps command truncating strings longer than 256 bytes#5997
cheese-cakee wants to merge 6 commits intorizinorg:devfrom
cheese-cakee:fix-ps-long-strings

Conversation

@cheese-cakee
Copy link

@cheese-cakee cheese-cakee commented Mar 4, 2026

Fixes #4857

The ps command and its variants truncate strings longer than 256 bytes because they depend on core->blocksize. This PR decouples string reading from the static block by switching to RzBuffer for dynamic streaming reads.

Changes

  • Replace const ut8 *buffer with RzBuffer *buffer and add ut64 offset field in RzStrStringifyOpt
  • Rewrite
    z_str_stringify_raw_buffer to use
    z_buf_read_at in small chunks instead of requiring a contiguous memory pointer
  • Update all ps handlers in cmd_print.c to create bounded RzBuffer wrappers
  • Add NULL checks on all
    z_buf_new_with_pointers return values
  • Add regression test for strings longer than 256 bytes in est/db/cmd/cmd_ps

@cheese-cakee cheese-cakee force-pushed the fix-ps-long-strings branch from 0cbb0e8 to 0cc9901 Compare March 4, 2026 20:13
@cheese-cakee cheese-cakee changed the title core: Fix ps truncating strings > 256 bytes (#4857) core: Fix ps command truncating strings longer than 256 bytes Mar 4, 2026
@cheese-cakee cheese-cakee marked this pull request as draft March 4, 2026 20:14
@cheese-cakee cheese-cakee marked this pull request as ready for review March 4, 2026 20:14
Refactor RzStrStringifyOpt to use RzBuffer for streaming reads
instead of depending on core->block size. This allows ps and its
variants to print strings of arbitrary length.

* Replace const ut8 *buffer with RzBuffer *buffer in RzStrStringifyOpt
* Rewrite rz_str_stringify_raw_buffer to use rz_buf_read_at in chunks
* Update all cmd_print.c ps handlers to create RzBuffer wrappers
* Add regression test for >256 byte strings
@cheese-cakee cheese-cakee force-pushed the fix-ps-long-strings branch from 0cc9901 to 2d00576 Compare March 4, 2026 20:54
@cheese-cakee cheese-cakee marked this pull request as draft March 4, 2026 22:41
@cheese-cakee cheese-cakee marked this pull request as ready for review March 5, 2026 21:56
@cheese-cakee
Copy link
Author

done

RzCodePoint code_point;
ut32 n_runes = 0;
int rsize = 1; // rune size
b = option->buffer;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is unnecessary, undo this and define variables in-place, like it was before. We use C99 standard, after all.

if (!section) {
return;
}
ut32 dlength = 0;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, it's unnecessary, move it back.

@notxvilka
Copy link
Contributor

See many compilation errors:

 clang -Ilibrz/util/librz_util.so.0.9.0.p -I. -I.. -Ilibrz -I../librz -Ilibrz/include -I../librz/include -Isubprojects/rzheap -I../subprojects/rzheap -Ilibrz/util/sdb/src -I../librz/util/sdb/src -Isubprojects/pcre2-10.47 -I../subprojects/pcre2-10.47 -I../subprojects/pcre2-10.47/src -I../subprojects/softfloat/include -Isubprojects/zlib-1.3.1 -I../subprojects/zlib-1.3.1 -I../subprojects/xz-5.8.1/src/liblzma/api -fdiagnostics-color=always -fsanitize=address,undefined -fno-omit-frame-pointer -D_FILE_OFFSET_BITS=64 -Wall -Winvalid-pch -Werror -O2 -g -DCC_SUPPORTS_W_ENUM_CONVERION -DCC_SUPPORTS_W_ENUM_COMPARE -std=gnu99 -Werror=sizeof-pointer-memaccess -fvisibility=hidden -DRZ_PLUGIN_INCORE=1 -shared-libasan -DSUPPORTS_PCRE2_JIT -DZYDIS_STATIC_BUILD -msse2 -D_GNU_SOURCE -DASAN=1 -DRZ_ASSERT_STDOUT=1 -fno-sanitize=function -fPIC -DLZMA_API_STATIC -pthread -MD -MQ librz/util/librz_util.so.0.9.0.p/alloc.c.o -MF librz/util/librz_util.so.0.9.0.p/alloc.c.o.d -o librz/util/librz_util.so.0.9.0.p/alloc.c.o -c ../librz/util/alloc.c
In file included from ../librz/util/alloc.c:4:
In file included from ../librz/include/rz_util.h:68:
../librz/include/rz_util/rz_str.h:280:25: error: redefinition of typedef 'RzBuffer' is a C11 feature [-Werror,-Wtypedef-redefinition]
  280 | typedef struct rz_buf_t RzBuffer;
      |                         ^
../librz/include/rz_util/rz_buf.h:18:25: note: previous definition is here
   18 | typedef struct rz_buf_t RzBuffer;
      |                         ^
1 error generated.

And more: https://github.com/rizinorg/rizin/actions/runs/22780588559/job/66129877540?pr=5997

@notxvilka notxvilka added the Requirements not met The PR doesn't meet the minimum contribution requirements. See CONTRIBUTING.md for details. label Mar 7, 2026
@notxvilka
Copy link
Contributor

Use the PR template!

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

Labels

API Requirements not met The PR doesn't meet the minimum contribution requirements. See CONTRIBUTING.md for details. rz-test RzCore RzUtil

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ps doesn't print long strings by default, because it depends on core->block.

3 participants