Skip to content

Commit

Permalink
SpotBugs bug on bitwise OR of signed byte computed
Browse files Browse the repository at this point in the history
  • Loading branch information
KoenDG committed Nov 5, 2023
1 parent fef8ff3 commit bd16b27
Showing 1 changed file with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1325,12 +1325,12 @@ else if (tilesDown * tilesAcross > 1) {
// but has the correct offset to the JPEG stream in the StripOffsets tag.
long realJPEGOffset = jpegOffset;

short expectedSOI = (short) (imageInput.readByte() << 8 | imageInput.readByte());
short expectedSOI = (short) (imageInput.readByte() << 8 | (imageInput.readByte() & 0xff));
if (expectedSOI != (short) JPEG.SOI) {
if (stripTileOffsets != null && stripTileOffsets.length == 1) {
imageInput.seek(stripTileOffsets[0]);

expectedSOI = (short) (imageInput.readByte() << 8 | imageInput.readByte());
expectedSOI = (short) (imageInput.readByte() << 8 | (imageInput.readByte() & 0xff));
if (expectedSOI == (short) JPEG.SOI) {
realJPEGOffset = stripTileOffsets[0];
}
Expand All @@ -1356,7 +1356,7 @@ else if (tilesDown * tilesAcross > 1) {
// If the first tile stream starts with SOS, we'll correct offset/length
imageInput.seek(stripTileOffsets[0]);

if ((short) (imageInput.readByte() << 8 | imageInput.readByte()) == (short) JPEG.SOS) {
if ((short) (imageInput.readByte() << 8 | (imageInput.readByte() & 0xff)) == (short) JPEG.SOS) {
processWarningOccurred("Incorrect StripOffsets/TileOffsets, points to SOS marker, ignoring offsets/byte counts.");
int len = 2 + (imageInput.readUnsignedByte() << 8 | imageInput.readUnsignedByte());
stripTileOffsets[0] += len;
Expand Down Expand Up @@ -1530,7 +1530,7 @@ else if (tilesDown * tilesAcross > 1) {

// If the tile stream starts with SOS...
if (x == 0 && y == 0) {
if ((short) (imageInput.readByte() << 8 | imageInput.readByte()) == (short) JPEG.SOS) {
if ((short) (imageInput.readByte() << 8 | (imageInput.readByte() & 0xff)) == (short) JPEG.SOS) {
imageInput.seek(stripTileOffsets[i] + 14); // TODO: Read from SOS length from stream, in case of gray/CMYK
length -= 14;
}
Expand Down

0 comments on commit bd16b27

Please sign in to comment.