diff --git a/cpp/src/arrow/io/caching.cc b/cpp/src/arrow/io/caching.cc index 307b933d16ee3..bd61c40693a27 100644 --- a/cpp/src/arrow/io/caching.cc +++ b/cpp/src/arrow/io/caching.cc @@ -174,8 +174,9 @@ struct ReadRangeCache::Impl { // Add the given ranges to the cache, coalescing them where possible virtual Status Cache(std::vector ranges) { - ranges = internal::CoalesceReadRanges(std::move(ranges), options.hole_size_limit, - options.range_size_limit); + ARROW_ASSIGN_OR_RAISE( + ranges, internal::CoalesceReadRanges(std::move(ranges), options.hole_size_limit, + options.range_size_limit)); std::vector new_entries = MakeCacheEntries(ranges); // Add new entries, themselves ordered by offset if (entries.size() > 0) { diff --git a/cpp/src/arrow/io/interfaces.cc b/cpp/src/arrow/io/interfaces.cc index d3229fd067cbe..1d35549cc4345 100644 --- a/cpp/src/arrow/io/interfaces.cc +++ b/cpp/src/arrow/io/interfaces.cc @@ -425,7 +425,7 @@ ThreadPool* GetIOThreadPool() { namespace { struct ReadRangeCombiner { - std::vector Coalesce(std::vector ranges) { + Result> Coalesce(std::vector ranges) { if (ranges.empty()) { return ranges; } @@ -454,7 +454,9 @@ struct ReadRangeCombiner { const auto& left = ranges[i]; const auto& right = ranges[i + 1]; DCHECK_LE(left.offset, right.offset); - DCHECK_LE(left.offset + left.length, right.offset) << "Some read ranges overlap"; + if (left.offset + left.length > right.offset) { + return Status::IOError("Some read ranges overlap"); + } } #endif @@ -509,9 +511,9 @@ struct ReadRangeCombiner { }; // namespace -std::vector CoalesceReadRanges(std::vector ranges, - int64_t hole_size_limit, - int64_t range_size_limit) { +Result> CoalesceReadRanges(std::vector ranges, + int64_t hole_size_limit, + int64_t range_size_limit) { DCHECK_GT(range_size_limit, hole_size_limit); ReadRangeCombiner combiner{hole_size_limit, range_size_limit}; diff --git a/cpp/src/arrow/io/util_internal.h b/cpp/src/arrow/io/util_internal.h index b1d75d1d0bd1f..2015f6a211292 100644 --- a/cpp/src/arrow/io/util_internal.h +++ b/cpp/src/arrow/io/util_internal.h @@ -45,9 +45,9 @@ ARROW_EXPORT Status ValidateWriteRange(int64_t offset, int64_t size, int64_t fil ARROW_EXPORT Status ValidateRange(int64_t offset, int64_t size); ARROW_EXPORT -std::vector CoalesceReadRanges(std::vector ranges, - int64_t hole_size_limit, - int64_t range_size_limit); +Result> CoalesceReadRanges(std::vector ranges, + int64_t hole_size_limit, + int64_t range_size_limit); ARROW_EXPORT ::arrow::internal::ThreadPool* GetIOThreadPool(); diff --git a/cpp/src/parquet/file_reader.cc b/cpp/src/parquet/file_reader.cc index 5247b9d4b543d..edf5b5ed7570b 100644 --- a/cpp/src/parquet/file_reader.cc +++ b/cpp/src/parquet/file_reader.cc @@ -139,8 +139,10 @@ const RowGroupMetaData* RowGroupReader::metadata() const { return contents_->met ::arrow::io::ReadRange ComputeColumnChunkRange(FileMetaData* file_metadata, int64_t source_size, int row_group_index, int column_index) { - auto row_group_metadata = file_metadata->RowGroup(row_group_index); - auto column_metadata = row_group_metadata->ColumnChunk(column_index); + std::unique_ptr row_group_metadata = + file_metadata->RowGroup(row_group_index); + std::unique_ptr column_metadata = + row_group_metadata->ColumnChunk(column_index); int64_t col_start = column_metadata->data_page_offset(); if (column_metadata->has_dictionary_page() &&