-
Notifications
You must be signed in to change notification settings - Fork 485
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ORC-1528: Fix readBytes potential overflow in RecordReaderUtils.ChunkReader#create #1662
Changes from 1 commit
ffc6b16
88aecc6
a9f325f
c6cc177
1869d72
4f9dfc2
26b3501
0e6c74a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -770,18 +770,18 @@ void readRanges(FSDataInputStream file, boolean allocateDirect, double extraByte | |||||||||||
} | ||||||||||||
|
||||||||||||
static ChunkReader create(BufferChunk from, BufferChunk to) { | ||||||||||||
long f = Integer.MAX_VALUE; | ||||||||||||
long e = Integer.MIN_VALUE; | ||||||||||||
long f = Long.MAX_VALUE; | ||||||||||||
long e = Long.MIN_VALUE; | ||||||||||||
|
||||||||||||
long cf = Integer.MAX_VALUE; | ||||||||||||
long ef = Integer.MIN_VALUE; | ||||||||||||
int reqBytes = 0; | ||||||||||||
long cf = Long.MAX_VALUE; | ||||||||||||
long ef = Long.MIN_VALUE; | ||||||||||||
long reqBytes = 0L; | ||||||||||||
|
||||||||||||
BufferChunk current = from; | ||||||||||||
while (current != to.next) { | ||||||||||||
f = Math.min(f, current.getOffset()); | ||||||||||||
e = Math.max(e, current.getEnd()); | ||||||||||||
if (ef == Integer.MIN_VALUE || current.getOffset() <= ef) { | ||||||||||||
if (ef == Long.MIN_VALUE || current.getOffset() <= ef) { | ||||||||||||
cf = Math.min(cf, current.getOffset()); | ||||||||||||
ef = Math.max(ef, current.getEnd()); | ||||||||||||
} else { | ||||||||||||
|
@@ -792,7 +792,14 @@ static ChunkReader create(BufferChunk from, BufferChunk to) { | |||||||||||
current = (BufferChunk) current.next; | ||||||||||||
} | ||||||||||||
reqBytes += ef - cf; | ||||||||||||
return new ChunkReader(from, to, (int) (e - f), reqBytes); | ||||||||||||
if (reqBytes >= Integer.MAX_VALUE) { | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I think it might be more accurate to extract and reuse this MAX_ARRAY_SIZE constant, the java maximum array length is not actually Integer.MAX_VALUE .
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should I define a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I tend to extract it into a utility class (e.g. IOUtils) and reuse the same constant. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should remove There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree "the same concept should be kept in a single source". Should we include the changes to remove the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @guiyanakuang Considering that this PR has been closed, is it still necessary to continue the discussion on the issues mentioned above? |
||||||||||||
throw new IllegalArgumentException("invalid reqBytes value " + reqBytes + ",out of bounds " + Integer.MAX_VALUE); | ||||||||||||
} | ||||||||||||
long readBytes = e - f; | ||||||||||||
if (readBytes >= Integer.MAX_VALUE) { | ||||||||||||
throw new IllegalArgumentException("invalid readBytes value " + readBytes + ",out of bounds " + Integer.MAX_VALUE); | ||||||||||||
} | ||||||||||||
return new ChunkReader(from, to, (int) readBytes, (int) reqBytes); | ||||||||||||
} | ||||||||||||
|
||||||||||||
static ChunkReader create(BufferChunk from, int minSeekSize) { | ||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Recommendation: This is already existing so please feel free to ignore.
Since we are touching the code, Can we rename the variables for easy reading?
Couldn't understand the meaning of f, e, cf, ce 😢
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great, let me try.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, I'm opposite to @mystic-lama 's comment.
We don't want to mix a bug fix and a style fix (or refactorying) in the same PR. It's because it increases the review complexity indeed.
If we want to rename this, it should be done before or after this PR.
Please don't change the existing variable name in this PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ack, @dongjoon-hyun has a point. @yebukong we can do that in follow up PR or may be leave it as is :)
Apologies for the noise.