From 0db820a6c1e5771055841f192b17adf0638f48b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Mon, 27 Apr 2026 19:51:04 +0800 Subject: [PATCH] Binary: skips short string entirely to improve performance Co-authored-by: Copilot --- src/common/impl/binary_apple.c | 3 +-- src/common/impl/binary_linux.c | 3 ++- src/common/impl/binary_windows.c | 3 ++- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/common/impl/binary_apple.c b/src/common/impl/binary_apple.c index d3358460d..de2c87638 100644 --- a/src/common/impl/binary_apple.c +++ b/src/common/impl/binary_apple.c @@ -72,6 +72,7 @@ static bool handleMachSection(const FFMemoryMapping* mapping, const char* name, } uint32_t len = (uint32_t) strnlen(p, size - off); if (len < minLength) { + off += len; // Skip short strings continue; } if (*p >= ' ' && *p <= '~') { // Ignore control characters @@ -177,8 +178,6 @@ static const char* dumpMachHeader(const FFMemoryMapping* mapping, off_t offset, } } } - - return NULL; } return NULL; diff --git a/src/common/impl/binary_linux.c b/src/common/impl/binary_linux.c index 240e75870..ac04bf71b 100644 --- a/src/common/impl/binary_linux.c +++ b/src/common/impl/binary_linux.c @@ -112,8 +112,9 @@ const char* ffBinaryExtractStrings(const char* elfFile, bool (*cb)(const char* s if (*p == '\0') { continue; } - uint32_t len = (uint32_t) strlen(p); + uint32_t len = (uint32_t) strnlen(p, data->d_size - off); if (len < minLength) { + off += len; continue; } // Only process printable ASCII characters diff --git a/src/common/impl/binary_windows.c b/src/common/impl/binary_windows.c index 9dc21e591..4bf2f4644 100644 --- a/src/common/impl/binary_windows.c +++ b/src/common/impl/binary_windows.c @@ -49,8 +49,9 @@ const char* ffBinaryExtractStrings(const char* peFile, bool (*cb)(const char* st if (*p == '\0') { continue; } - uint32_t len = (uint32_t) strlen(p); + uint32_t len = (uint32_t) strnlen(p, section->SizeOfRawData - off); if (len < minLength) { + off += len; continue; } // Only process printable ASCII characters