Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion c++/src/RLEv1.cc
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,10 @@ namespace orc {

signed char RleDecoderV1::readByte() {
SCOPED_MINUS_STOPWATCH(metrics, DecodingLatencyUs);
if (bufferStart_ == bufferEnd_) {
// Use >= rather than == so that a cursor which has already overshot the
// buffer end (bufferStart_ > bufferEnd_) still triggers a refill instead of
// dereferencing out of bounds.
if (bufferStart_ >= bufferEnd_) {
int bufferLength;
const void* bufferPointer;
if (!inputStream_->Next(&bufferPointer, &bufferLength)) {
Expand Down
6 changes: 5 additions & 1 deletion c++/src/RLEv2.hh
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,11 @@ namespace orc {
}

uint64_t bufLength() {
return bufferEnd_ - bufferStart_;
// Guard against a cursor that has overshot the buffer end. If bufferStart_
// has advanced past bufferEnd_, the raw pointer difference is negative and
// would underflow to a huge value when returned as unsigned, defeating the
// std::min clamps in the bit-unpacking fast loops (BpackingDefault.cc).
return bufferEnd_ > bufferStart_ ? static_cast<uint64_t>(bufferEnd_ - bufferStart_) : 0;
}

void setBitsLeft(const uint32_t bits) {
Expand Down
5 changes: 4 additions & 1 deletion c++/src/RleDecoderV2.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ namespace orc {

unsigned char RleDecoderV2::readByte() {
SCOPED_MINUS_STOPWATCH(metrics, DecodingLatencyUs);
if (bufferStart_ == bufferEnd_) {
// Use >= rather than == so that a cursor which has already overshot the
// buffer end (bufferStart_ > bufferEnd_) still triggers a refill instead of
// dereferencing out of bounds.
if (bufferStart_ >= bufferEnd_) {
int bufferLength;
const void* bufferPointer;
if (!inputStream_->Next(&bufferPointer, &bufferLength)) {
Expand Down