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
Fix integer overflow in more offset calculations #224
Conversation
31086f4
to
299bae9
Compare
/cc @adamkeyser @manuelq |
299bae9
to
07a9401
Compare
Prefer `(long)ordinal * bitsPerX` as the idiom.
07a9401
to
cda75b7
Compare
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.
This looks great! hopefully we can get a release soon :)
@toolbear @Test
public void testLarge() throws IOException {
int listOrdinal = 0; //2147483647 MAX INT
int totalRecords = 0; // WHY 79536431 because bitsPerListPointer = 27 so MaxINT/27
for(int ordinal = 0; ordinal <= 79536431;ordinal++){
addRecord(listOrdinal++);
totalRecords++;
}
//Just add another 100k
System.out.println(totalRecords);
for(int ordinal = 0; ordinal <= 100000;ordinal++){
addRecord(listOrdinal++);
totalRecords++;
}
System.out.println(totalRecords);
roundTripSnapshot();
HollowListTypeReadState typeState = (HollowListTypeReadState) readStateEngine.getTypeState("TestList");
assertList(typeState, 14, 14);
assertList(typeState, 79636430, 79636430);
HollowChecksum checksum = typeState.getChecksum(readStateEngine.getSchema("TestList"));
checksum.intValue();
} |
On the master branch the test above throws
|
…_test to master * commit 'b637bb0c0ef9d6551bfc3f4743defff27b7c3dc5': Add hostname to smoke test data track
Fixing more cases of integer overflow similar to those fixed in #222.
identify potential overflow and upcast to
long
ordinal * bitsPerX
where both areint
; can bebucket
orelement
in addition toordinal
ordinal + N
where ordinal is assigned to along
or passed as an argument that acceptslong
sBitSet
which only works withint
indices; this is one of the reasons ordinals are currently limited to integersstandardize style on
(long)ordinal * bitsPerX
to make it easier to spot the common pattern and notice missing upcasts(long)bitsPerX * ordinal
,bitsPerX * (long)ordinal
, or(long)bitsPerX * (long)ordinal
ordinal * (long)bitsPerX
or(long)ordinal * (long)bitsPerX
ordinal
is already a long temporary variable or passed as long to a private helper; public APIs should only pass ordinal asint
to avoid confusionreview
com.netflix.hollow.core.read.engine
list.*
set.*
map.*
object.*