-
Notifications
You must be signed in to change notification settings - Fork 73
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(core-clp): Handle 0-byte reads when BufferReader
's underlying buffer is fully consumed.
#687
fix(core-clp): Handle 0-byte reads when BufferReader
's underlying buffer is fully consumed.
#687
Conversation
WalkthroughThe pull request modifies the Changes
Suggested reviewers
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
⏰ Context from checks skipped due to timeout of 90000ms (11)
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
components/core/src/clp/BufferReader.cpp (1)
63-66
: Consider adding a comment to document the 0-byte read behaviour.While the implementation is correct, it would be helpful to add a comment explaining that 0-byte reads are valid operations that always succeed. This would help future maintainers understand the intentional behaviour.
+ // A request to read 0 bytes is always successful, regardless of the buffer state if (0 == num_bytes_to_read) { num_bytes_read = 0; return ErrorCode_Success; }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
components/core/src/clp/BufferReader.cpp
(1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
components/core/src/clp/BufferReader.cpp (1)
Pattern **/*.{cpp,hpp,java,js,jsx,ts,tsx}
: - Prefer false == <expression>
rather than !<expression>
.
⏰ Context from checks skipped due to timeout of 90000ms (12)
- GitHub Check: centos-stream-9-static-linked-bins
- GitHub Check: ubuntu-focal-static-linked-bins
- GitHub Check: ubuntu-jammy-static-linked-bins
- GitHub Check: ubuntu-focal-dynamic-linked-bins
- GitHub Check: centos-stream-9-dynamic-linked-bins
- GitHub Check: ubuntu-jammy-dynamic-linked-bins
- GitHub Check: build-macos (macos-14, false)
- GitHub Check: build-macos (macos-14, true)
- GitHub Check: lint-check (ubuntu-latest)
- GitHub Check: build-macos (macos-13, false)
- GitHub Check: build (macos-latest)
- GitHub Check: build-macos (macos-13, true)
🔇 Additional comments (1)
components/core/src/clp/BufferReader.cpp (1)
63-66
: LGTM! The implementation correctly handles 0-byte reads.The added check properly handles the case when no bytes are requested to be read, preventing unnecessary EndOfFile errors. This aligns well with the PR's objective of fixing 0-byte reads when deserializing empty strings.
@@ -60,6 +60,11 @@ auto BufferReader::try_read(char* buf, size_t num_bytes_to_read, size_t& num_byt | |||
throw OperationFailed(ErrorCode_BadParam, __FILENAME__, __LINE__); | |||
} | |||
|
|||
if (0 == num_bytes_to_read) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One concern, when only I read this code, I thought the copy doesn't handle 0 bytes copy.
Then after reading the case description, I realized that the issue is when (0 == remaining_data_size).
If I were to write this code, I might put this if-clause under (0 == remaining_data_size). That said, I feel it's also ok to handle the 0 bytes read earlier so the function doesn't do unnecessary work.
Up to you which you choose.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I put it this way mainly for efficiency. I could move it inside the if block
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me. The title looks ok as well.
Description
The current
BufferReader
implementation doesn't handle cases when reading 0-byte from a fully consumed buffer. This error was triggered when using it in Python ffi library to deserialize an empty string value at the end of the buffer. The size of string is zero, meaning that we don't have to read any bytes from the underlying buffer, but the buffer still returns EndOfFile, and thus causing an incomplete IR exception.This PR fixes this problem by adding a check for 0-byte reads.
Validation performed
Summary by CodeRabbit