Widen volumeHandle to long before shifting by 48 (CodeQL java/lshift-larger-than-type-width)#231
Open
vharseko wants to merge 2 commits into
Open
Conversation
…larger-than-type-width) In IOMeter.dump() the composite event key was built as "(volumeHandle << 48) + pageAddress". volumeHandle is an int, and Java uses only the low 5 bits of an int shift distance, so "<< 48" was silently evaluated as "<< 16" in 32-bit arithmetic before being widened to long. The handle therefore placed volumeHandle in the wrong bit range (and could overflow int), so events for different volumes/pages could collide on the same HashMap key when dumping with analyzePages. Cast volumeHandle to long first so the shift is performed in 64 bits: ((long) volumeHandle << 48) + pageAddress. This only affects the -a page analysis of the journal dump utility.
maximthomas
approved these changes
Jul 8, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Resolves the single
java/lshift-larger-than-type-widthCodeQL alert inIOMeter.java.IOMeter.dump()builds a composite key that groups journal events by(volumeHandle, pageAddress):volumeHandleis anint, and Java masks anintshift distance to its low5 bits, so
<< 48is actually evaluated as<< (48 & 31)=<< 16in 32-bitarithmetic and only then widened to
long. As a result:volumeHandle << 16can overflowint,so events for different volumes/pages can collide on the same
HashMapkey.Fix
Cast to
longbefore the shift so it is performed in 64 bits:This only affects the
-a(analyze pages) mode of the journal-dump diagnosticutility; it is not on a data path.
Testing
mvn -o -pl persistit/core -am compile— BUILD SUCCESS.