Skip to content

Commit a85515e

Browse files
committed
Fix Integer Overflow in Seekable(Array|File)InputStream::Skip
1 parent 56063c2 commit a85515e

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)