Skip to content

MOD-13010: Fix cmp_strings() - correctly handle binary data with embedded NULLs#7765

Merged
nafraf merged 3 commits intomasterfrom
nafraf_mod-13010
Dec 14, 2025
Merged

MOD-13010: Fix cmp_strings() - correctly handle binary data with embedded NULLs#7765
nafraf merged 3 commits intomasterfrom
nafraf_mod-13010

Conversation

@nafraf
Copy link
Collaborator

@nafraf nafraf commented Dec 12, 2025

Describe the changes in the pull request

A clear and concise description of what the PR is solving, including:

  1. Current:
    Since cmp_strings() uses strcmp() the comparison ends when the first NULL character is found, and this causes wrong results when cmp_strings() is used for the comparison of byte strings.
  2. Change:
    cmp_strings() is modified to use memcmp() instead of strcmp()
  3. Outcome:
    Right comparison of byte strings and text.

Note

Replace strncmp with memcmp in string comparison to support embedded NULs and add a test ensuring aggregate results are coherent with binary strings.

  • Core:
    • Update cmp_strings in src/value/value.c to use memcmp (instead of strncmp) for length-aware comparison supporting binary data with embedded \0.
  • Tests:
    • Add test_mod_13010 in tests/pytests/test_issues.py verifying coherence between FT.AGGREGATE queries with and without GROUPBY when values contain embedded NULs.

Written by Cursor Bugbot for commit 89baa58. This will update automatically on new commits. Configure here.

@nafraf nafraf changed the title MOD-13010: Fix wrong TOLIST MOD-13010: Fix cmp_strings() Dec 12, 2025
@nafraf nafraf marked this pull request as ready for review December 14, 2025 02:55
@codecov
Copy link

codecov bot commented Dec 14, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 84.72%. Comparing base (fd1b5c2) to head (89baa58).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #7765      +/-   ##
==========================================
- Coverage   84.77%   84.72%   -0.06%     
==========================================
  Files         351      351              
  Lines       54761    54761              
  Branches    14727    14727              
==========================================
- Hits        46426    46398      -28     
- Misses       8136     8164      +28     
  Partials      199      199              
Flag Coverage Δ
flow 85.18% <100.00%> (-0.19%) ⬇️
unit 52.08% <100.00%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

static inline int cmp_strings(const char *s1, const char *s2, size_t l1, size_t l2) {
int cmp = strncmp(s1, s2, MIN(l1, l2));
// Use memcmp instead of strncmp to correctly handle binary data with embedded NULLs
int cmp = memcmp(s1, s2, MIN(l1, l2));
Copy link
Collaborator

Choose a reason for hiding this comment

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

Seems OK - memcmp is also comparing bytes, similar to strncmp - only supporting embedded nulls.
When comparing null-terminated strings - will behave the same as before - and no extra comparisons will be done.
When comparing slices, which can contain embedded nulls, will behave as expected.

@oshadmi oshadmi requested a review from kei-nan December 14, 2025 13:16
@kei-nan kei-nan changed the title MOD-13010: Fix cmp_strings() MOD-13010: Fix cmp_strings() - correctly handle binary data with embedded NULLs Dec 14, 2025
@nafraf nafraf added this pull request to the merge queue Dec 14, 2025
Merged via the queue into master with commit f13ba95 Dec 14, 2025
41 checks passed
@nafraf nafraf deleted the nafraf_mod-13010 branch December 14, 2025 16:38
@redisearch-backport-pull-request
Copy link
Contributor

Backport failed for 2.10, because it was unable to cherry-pick the commit(s).

Please cherry-pick the changes locally and resolve any conflicts.

git fetch origin 2.10
git worktree add -d .worktree/backport-7765-to-2.10 origin/2.10
cd .worktree/backport-7765-to-2.10
git switch --create backport-7765-to-2.10
git cherry-pick -x f13ba95b1fe3d52daf9aec12ac68873d25080efe

@redisearch-backport-pull-request
Copy link
Contributor

Backport failed for 8.4, because it was unable to cherry-pick the commit(s).

Please cherry-pick the changes locally and resolve any conflicts.

git fetch origin 8.4
git worktree add -d .worktree/backport-7765-to-8.4 origin/8.4
cd .worktree/backport-7765-to-8.4
git switch --create backport-7765-to-8.4
git cherry-pick -x f13ba95b1fe3d52daf9aec12ac68873d25080efe

@JoanFM
Copy link
Collaborator

JoanFM commented Dec 15, 2025

Should we aim to have some RSValue unit tests? or porting soon to Rust?

@nafraf nafraf mentioned this pull request Dec 15, 2025
2 tasks
github-merge-queue bot pushed a commit that referenced this pull request Dec 15, 2025
…th embedded NULLS (#7771)

MOD-13010: Fix cmp_strings() - correctly handle binary data with embedded NULLs (#7765)
(cherry picked from commit f13ba95)
nafraf added a commit that referenced this pull request Dec 15, 2025
nafraf added a commit that referenced this pull request Dec 15, 2025
github-merge-queue bot pushed a commit that referenced this pull request Dec 16, 2025
…h embedded NULLs (#7794)

MOD-13010: Fix cmp_strings() - correctly handle binary data with embedded NULLs (#7765)
(cherry picked from commit f13ba95)
github-merge-queue bot pushed a commit that referenced this pull request Dec 16, 2025
…h embedded NULLS (#7792)

MOD-13010: Fix cmp_strings() - correctly handle binary data with embedded NULLs (#7765)
(cherry picked from commit f13ba95)
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.

4 participants