Skip to content
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

NDPI: correct for potential integer overflow in stored restart marker tag #4083

Merged
merged 2 commits into from
Oct 3, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions components/formats-gpl/src/loci/formats/in/NDPIReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ public class NDPIReader extends BaseTiffReader {
private static final int TISSUE_INDEX = 65425;
private static final int MARKER_TAG = 65426;
private static final int REFERENCE = 65427;
private static final int MARKER_TAG_HIGH_BYTES = 65432;
private static final int FILTER_SET_NAME = 65434;
private static final int EXPOSURE_RATIO = 65435;
private static final int RED_MULTIPLIER = 65436;
Expand Down Expand Up @@ -197,11 +198,34 @@ else if (useTiffParser(ifds.get(ifdIndex))) {
try {
service.close();
long[] markers = ifd.getIFDLongArray(MARKER_TAG);
long[] markerHighBytes = ifd.getIFDLongArray(MARKER_TAG_HIGH_BYTES);
if (!use64Bit) {
for (int i=0; i<markers.length; i++) {
markers[i] = markers[i] & 0xffffffffL;
}
}
else if (markerHighBytes != null) {
// 64-bit offsets expected
// markers need to be reconstructed from MARKER_TAG (lower 32 bits)
// and MARKER_TAG_HIGH_BYTES (upper 32 bits)
for (int i=0; i<markers.length; i++) {
if (i < markerHighBytes.length) {
markers[i] = markers[i] & 0xffffffffL;
markers[i] += (markerHighBytes[i] << 32);
}
}
}
else {
// 64-bit offsets expected, but upper 32 bits not found
// this can happen in sub-resolution IFDs
// try to correct for offset overflow by adding 4GB to offsets, if appropriate
LOGGER.debug("Optional tag {} missing or unreadable", MARKER_TAG_HIGH_BYTES);
for (int i=1; i<markers.length; i++) {
if (markers[i] < markers[i - 1]) {
markers[i] += (long) Math.pow(2, 32);
}
}
}
if (markers != null) {
service.setRestartMarkers(markers);
}
Expand Down