Copilot commented on code in PR #875:
URL: https://github.com/apache/iceberg-cpp/pull/875#discussion_r4469689353
##########
src/iceberg/file_io.cc:
##########
@@ -69,21 +217,81 @@ Result<std::string> FileIO::ReadFile(const std::string&
file_location,
ICEBERG_ASSIGN_OR_RAISE(input_file, NewInputFile(file_location));
ICEBERG_ASSIGN_OR_RAISE(read_size, input_file->Size());
}
- if (read_size < 0) {
- return Invalid("Invalid negative file size {} for {}", read_size,
file_location);
+ return ReadInputFile(*input_file, read_size, file_location);
+}
+
+Result<std::unique_ptr<InputFile>> FileIO::NewCachedInputFile(
+ std::string file_location, std::optional<size_t> length) {
+ std::unique_ptr<InputFile> input_file;
+ if (length.has_value()) {
+ ICEBERG_ASSIGN_OR_RAISE(input_file, NewInputFile(file_location, *length));
Review Comment:
`NewCachedInputFile` forwards `*length` to the virtual `NewInputFile` before
applying the same `int64_t` range check that `ReadFile` performs first. A
custom `FileIO` can therefore truncate or issue an invalid range request for a
`size_t` value above `int64_t::max()` before this method returns an error.
Validate the length before invoking the virtual method, matching `ReadFile`'s
ordering.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]