Skip to content

Fix index error of CRLF when replying with integer-encoded strings#13711

Merged
ShooterIT merged 3 commits intoredis:unstablefrom
raffertyyu:unstable
Dec 31, 2024
Merged

Fix index error of CRLF when replying with integer-encoded strings#13711
ShooterIT merged 3 commits intoredis:unstablefrom
raffertyyu:unstable

Conversation

@raffertyyu
Copy link
Copy Markdown
Contributor

close #13709

fix the index error of CRLF character in addReplyBulk function.

@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Dec 29, 2024

CLA assistant check
All committers have signed the CLA.

@mgravell
Copy link
Copy Markdown
Contributor

If correct, this is a severe bug; it'll insta-break many clients (or at least any that enforce inbound protocol correctness)

@raffertyyu
Copy link
Copy Markdown
Contributor Author

If correct, this is a severe bug; it'll insta-break many clients (or at least any that enforce inbound protocol correctness)

Yeah, that's the second question I'm thinking about. This bug is introduced in last month(a106198), but the existings tcl test scripts couldn't find it. redis-cli could parse the returned content correctly. Why?

@mgravell
Copy link
Copy Markdown
Contributor

mgravell commented Dec 29, 2024

A client could silently just skip the trailing 2 bytes without enforcing them. I know for sure that my client will not like this malformed data.

@sundb
Copy link
Copy Markdown
Collaborator

sundb commented Dec 30, 2024

@raffertyyu thanks, please also make a test(using readraw) to cover it.

sundb
sundb previously approved these changes Dec 31, 2024
Copy link
Copy Markdown
Collaborator

@sundb sundb left a comment

Choose a reason for hiding this comment

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

LGTM

@sundb sundb requested a review from ShooterIT December 31, 2024 01:26
@sundb
Copy link
Copy Markdown
Collaborator

sundb commented Dec 31, 2024

Copy link
Copy Markdown
Member

@ShooterIT ShooterIT left a comment

Choose a reason for hiding this comment

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

LGTM

@ShooterIT ShooterIT changed the title fix index error of CRLF when replying int encoding string. fix index error of CRLF when replying with integer-encoded strings Dec 31, 2024
@ShooterIT ShooterIT changed the title fix index error of CRLF when replying with integer-encoded strings Fix index error of CRLF when replying with integer-encoded strings Dec 31, 2024
@ShooterIT ShooterIT merged commit 04f63d4 into redis:unstable Dec 31, 2024
@ShooterIT
Copy link
Copy Markdown
Member

thank you @raffertyyu merged

@sundb sundb removed this from Redis 8.2 Aug 15, 2025
@sundb sundb added this to Redis 8.0 Aug 15, 2025
@sundb sundb moved this from Todo to Done in Redis 8.0 Aug 15, 2025
@oranagra
Copy link
Copy Markdown
Member

i have a branch in which robj is a little bigger, and in that case, this value (-9223372036854775809) doesn't fit into embstr.

  1. i wonder why the test is so specific and if it can't / shouldn't be change to be more flexible (not to expect specific encoding).
  2. the rawread (with exact number of characters it expects), specifically for the encoding check seems really excessive, and can cause the test to hang (rather than fail) if the response is shorter (it was annoying to debug)

@sundb
Copy link
Copy Markdown
Collaborator

sundb commented Aug 21, 2025

  1. the rawread (with exact number of characters it expects), specifically for the encoding check seems really excessive, and can cause the test to hang (rather than fail) if the response is shorter (it was annoying to debug)

@oranagra Perhaps when readraw is enabled, we could return a full protocol response when executing a command, instead of only returning a single line.

like:

    r readraw 0
    assert_equal "\$16\r\naaaaaaaaaaaaaaaa\r\n" [r get crlf]

@oranagra
Copy link
Copy Markdown
Member

for that the reader needs to understand what it reads and know how much to read.
it might be good enough for most usages of rawread, but not for some, so we'll need both.
anyway, i argue that it's completely unnecessary for this ENCODING command, and also that the test is too specific and fragile, if it intended to check the protocol, why does it even bother to test encoding..

@sundb sundb mentioned this pull request Aug 26, 2025
sundb added a commit that referenced this pull request Aug 27, 2025
This PR mainly fixes two flakiness tests.
1. Fix the failure of `Active Defrag HFE with ebrax` test in
`memefficiency.tcl`
When `redisObject` structure size changes, the current test design
becomes flakiness:
In the current test, we will create 1 hash key + N string keys. When we
delete this string key, these hash keys may be evenly distributed in
robj 's slabs, resulting in the inability to perform defragmentation.

2. Fix `bulk reply protocol` test in `protocol.tcl` introduced by
#13711
When `OBJ_ENCODING_EMBSTR_SIZE_LIMIT` (currently 44) changes, it can
cause this test to fail. This isn't necessarily a problem, but the main
issue is that we use `rawread` to verify encoding correctness. If the
reply length doesn't match exactly, it can cause the test to hang and
become difficult to debug.
funny-dog pushed a commit to funny-dog/redis that referenced this pull request Sep 17, 2025
…edis#13711)

close redis#13709

Fix the index error of CRLF character for integer-encoded strings
in addReplyBulk function

---------

Co-authored-by: debing.sun <debing.sun@redis.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

[BUG] wrong content returned by redis-server

6 participants