-
Notifications
You must be signed in to change notification settings - Fork 4.1k
GH-49896: [C++] Reject short buffer reads in IPC reader #49897
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -267,8 +267,9 @@ class ARROW_EXPORT RandomAccessFile : public InputStream, public Seekable { | |
|
|
||
| /// \brief Read data from given file position. | ||
| /// | ||
| /// At most `nbytes` bytes are read. The number of bytes read is returned | ||
| /// (it can be less than `nbytes` if EOF is reached). | ||
| /// At most `nbytes` bytes are read. The number of bytes read is returned. | ||
| /// If `allow_short_read` is true, the number of bytes read can be less than | ||
| /// `nbytes` if EOF is reached, otherwise an error is returned. | ||
| /// | ||
| /// This method can be safely called from multiple threads concurrently. | ||
| /// It is unspecified whether this method updates the file position or not. | ||
|
|
@@ -279,24 +280,56 @@ class ARROW_EXPORT RandomAccessFile : public InputStream, public Seekable { | |
| /// | ||
| /// \param[in] position Where to read bytes from | ||
| /// \param[in] nbytes The number of bytes to read | ||
| /// \param[in] allow_short_read Whether to allow reading less than `nbytes` | ||
| /// \param[out] out The buffer to read bytes into | ||
| /// \return The number of bytes read, or an error | ||
| virtual Result<int64_t> ReadAt(int64_t position, int64_t nbytes, bool allow_short_read, | ||
| void* out); | ||
|
|
||
| /// \brief Read data from given file position. | ||
| /// | ||
| /// Like `ReadAt(position, nbytes, allow_short_read, out)` with `allow_short_read` | ||
| /// set to true. | ||
|
Comment on lines
+291
to
+292
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder if we should deprecate these overloads over time (it feels like it would be safer to have
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. By "these overloads", you mean those without the And, yes, I agree that disallowing short reads by default would definitely be safer. Short reads by default is fine in a "safe" language like Python, not so much in C++.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, I think it would be safer if they were eventually removed to avoid this cropping up.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah sorry I missed your comment above. Yes, I agree, we should do that in a later PR.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (I'll open a separate issue and PR for deprecation) |
||
| /// | ||
| /// \param[in] position Where to read bytes from | ||
| /// \param[in] nbytes The number of bytes to read | ||
| /// \param[out] out The buffer to read bytes into | ||
| /// \return The number of bytes read, or an error | ||
| virtual Result<int64_t> ReadAt(int64_t position, int64_t nbytes, void* out); | ||
|
|
||
| /// \brief Read data from given file position. | ||
| /// | ||
| /// At most `nbytes` bytes are read, but it can be less if EOF is reached. | ||
| /// At most `nbytes` bytes are read. If `allow_short_read` is true, the | ||
| /// number of bytes read can be less than `nbytes` if EOF is reached, | ||
| /// otherwise an error is returned. | ||
| /// | ||
| /// \param[in] position Where to read bytes from | ||
| /// \param[in] nbytes The number of bytes to read | ||
| /// \param[in] allow_short_read Whether to allow reading less than `nbytes` | ||
| /// \return A buffer containing the bytes read, or an error | ||
| virtual Result<std::shared_ptr<Buffer>> ReadAt(int64_t position, int64_t nbytes, | ||
| bool allow_short_read); | ||
|
|
||
| /// \brief Read data from given file position. | ||
| /// | ||
| /// Like `ReadAt(position, nbytes, allow_short_read)` with `allow_short_read` | ||
| /// set to true. | ||
| /// | ||
| /// \param[in] position Where to read bytes from | ||
| /// \param[in] nbytes The number of bytes to read | ||
| /// \return A buffer containing the bytes read, or an error | ||
| virtual Result<std::shared_ptr<Buffer>> ReadAt(int64_t position, int64_t nbytes); | ||
|
|
||
| /// EXPERIMENTAL: Read data asynchronously. | ||
| virtual Future<std::shared_ptr<Buffer>> ReadAsync(const IOContext&, int64_t position, | ||
| int64_t nbytes, | ||
| bool allow_short_read); | ||
| virtual Future<std::shared_ptr<Buffer>> ReadAsync(const IOContext&, int64_t position, | ||
| int64_t nbytes); | ||
|
|
||
| /// EXPERIMENTAL: Read data asynchronously, using the file's IOContext. | ||
| Future<std::shared_ptr<Buffer>> ReadAsync(int64_t position, int64_t nbytes, | ||
| bool allow_short_read); | ||
| Future<std::shared_ptr<Buffer>> ReadAsync(int64_t position, int64_t nbytes); | ||
|
|
||
| /// EXPERIMENTAL: Explicit multi-read. | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.