Skip to content

Commit 65401ba

Browse files
committed
Fix Integer Overflow in Seekable(Array|File)InputStream::Skip
(cherry picked from commit 589d5ca) Signed-off-by: Dongjoon Hyun <dongjoon@apache.org>
1 parent 6883f8b commit 65401ba

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

c++/src/io/InputStream.cc

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ namespace orc {
102102
bool SeekableArrayInputStream::Skip(int count) {
103103
if (count >= 0) {
104104
uint64_t unsignedCount = static_cast<uint64_t>(count);
105-
if (unsignedCount + position_ <= length_) {
105+
if (unsignedCount <= length_ - position_) {
106106
position_ += unsignedCount;
107107
return true;
108108
} else {
@@ -186,7 +186,11 @@ namespace orc {
186186
return false;
187187
}
188188
uint64_t count = static_cast<uint64_t>(signedCount);
189-
position_ = std::min(position_ + count, length_);
189+
if (count > length_ - position_) {
190+
position_ = length_;
191+
} else {
192+
position_ += count;
193+
}
190194
pushBack_ = 0;
191195
return position_ < length_;
192196
}

0 commit comments

Comments
 (0)