This is an automated email from the ASF dual-hosted git repository.
asf-gitbox-commits pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/pdfbox-jbig2.git
The following commit(s) were added to refs/heads/master by this push:
new aadb5b6 PDFBOX-5660: Sonar - Fix sign-extension issues in bitmap bit
manipulation by using int for bitwise operations
aadb5b6 is described below
commit aadb5b60ef19237d2aac0d408b8bca811c638853
Author: Maruan Sahyoun <[email protected]>
AuthorDate: Wed May 13 20:53:36 2026 +0200
PDFBOX-5660: Sonar - Fix sign-extension issues in bitmap bit manipulation
by using int for bitwise operations
---
src/main/java/org/apache/pdfbox/jbig2/Bitmap.java | 2 +-
.../java/org/apache/pdfbox/jbig2/decoder/mmr/MMRDecompressor.java | 7 ++++---
2 files changed, 5 insertions(+), 4 deletions(-)
diff --git a/src/main/java/org/apache/pdfbox/jbig2/Bitmap.java
b/src/main/java/org/apache/pdfbox/jbig2/Bitmap.java
index f071837..a860942 100644
--- a/src/main/java/org/apache/pdfbox/jbig2/Bitmap.java
+++ b/src/main/java/org/apache/pdfbox/jbig2/Bitmap.java
@@ -98,7 +98,7 @@ public class Bitmap
final int shift = 7 - bitOffset;
- final byte src = bitmapBytes[byteIndex];
+ final int src = bitmapBytes[byteIndex] & 0xff; // convert to int for
bitwise operations
if ((pixelValue & 1) == 1)
{
bitmapBytes[byteIndex] = (byte) (src | (1 << shift));
diff --git
a/src/main/java/org/apache/pdfbox/jbig2/decoder/mmr/MMRDecompressor.java
b/src/main/java/org/apache/pdfbox/jbig2/decoder/mmr/MMRDecompressor.java
index 24db38d..5fb5d2a 100644
--- a/src/main/java/org/apache/pdfbox/jbig2/decoder/mmr/MMRDecompressor.java
+++ b/src/main/java/org/apache/pdfbox/jbig2/decoder/mmr/MMRDecompressor.java
@@ -567,7 +567,7 @@ public class MMRDecompressor
int x = 0;
int targetByte = result.getByteIndex(0, line);
- byte targetByteValue = 0;
+ int targetByteValue = 0;
for (int index = 0; index < count; index++)
{
@@ -590,16 +590,17 @@ public class MMRDecompressor
if ((x & 7) == 0)
{
- result.setByte(targetByte++, targetByteValue);
+ result.setByte(targetByte++, (byte) targetByteValue);
targetByteValue = 0;
}
}
}
+ // Flush remaining bits in the last partial byte
if ((x & 7) != 0)
{
targetByteValue <<= 8 - (x & 7);
- result.setByte(targetByte, targetByteValue);
+ result.setByte(targetByte, (byte) targetByteValue);
}
}