Do not invoke memcpy unless number of bytes to read greater than 0. Return more informative error message

Change-Id: I335736571e56af36f4de909e35f8d667693db7fe
This commit is contained in:
Wes McKinney committed 2018-02-26 15:42:39 -05:00
1 parent 90787ec89f
commit e3a590ed24
3 files changed
+13 -5

No files matched your search

+4 -2
View File
@@ -257,9 +257,11 @@ Status BufferReader::Tell(int64_t* position) const {
bool BufferReader::supports_zero_copy() const { return true; }
Status BufferReader::Read(int64_t nbytes, int64_t* bytes_read, void* buffer) {
memcpy(buffer, data_ + position_, nbytes);
*bytes_read = std::min(nbytes, size_ - position_);
position_ += *bytes_read;
if (*bytes_read) {
memcpy(buffer, data_ + position_, *bytes_read);
position_ += *bytes_read;
}
return Status::OK();
}
+5 -2
View File
@@ -756,8 +756,11 @@ TEST_F(TestTensorRoundTrip, NonContiguous) {
}
TEST(TestRecordBatchStreamReader, MalformedInput) {
auto empty = std::make_shared<Buffer>("");
auto garbage = std::make_shared<Buffer>("12345678");
const std::string empty_str = "";
const std::string garbage_str = "12345678";
auto empty = std::make_shared<Buffer>(empty_str);
auto garbage = std::make_shared<Buffer>(garbage_str);
std::shared_ptr<RecordBatchReader> batch_reader;
+4 -1
View File
@@ -227,7 +227,10 @@ Status ReadMessage(io::InputStream* file, std::unique_ptr<Message>* message) {
std::shared_ptr<Buffer> metadata;
RETURN_NOT_OK(file->Read(message_length, &metadata));
if (metadata->size() != message_length) {
return Status::IOError("Unexpected end of stream trying to read message");
std::stringstream ss;
ss << "Expected to read " << message_length << " metadata bytes, but "
<< "only read " << metadata->size();
return Status::Invalid(ss.str());
}
return Message::ReadFrom(metadata, file, message);