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 8e90642  PDFBOX-6162: Deep-copy CX state for safe JBIG2 context reuse 
across segments
8e90642 is described below

commit 8e9064248940b98eaa14bade284722b9c74f012d
Author: Maruan Sahyoun <[email protected]>
AuthorDate: Fri Apr 24 10:34:06 2026 +0200

    PDFBOX-6162: Deep-copy CX state for safe JBIG2 context reuse across segments
---
 .../org/apache/pdfbox/jbig2/decoder/arithmetic/CX.java | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/src/main/java/org/apache/pdfbox/jbig2/decoder/arithmetic/CX.java 
b/src/main/java/org/apache/pdfbox/jbig2/decoder/arithmetic/CX.java
index adc5e60..a5037ba 100644
--- a/src/main/java/org/apache/pdfbox/jbig2/decoder/arithmetic/CX.java
+++ b/src/main/java/org/apache/pdfbox/jbig2/decoder/arithmetic/CX.java
@@ -74,4 +74,22 @@ public final class CX
     {
         this.index = index;
     }
+
+    /**
+     * Creates and returns a deep copy of this {@code CX} object.
+     * The new instance will have the same context values, probability 
estimates,
+     * and current index as this object, but will be a separate instance.
+     * Changes to the copied object will not affect the original, and vice 
versa.
+     *
+     * <p>This is required when reusing arithmetic coding contexts across 
segments,
+     * to avoid sharing mutable probability state between decoders.</p>
+     *
+     * @return A new {@code CX} object with the same internal state as this 
object.
+     */
+    public CX copy() {
+        CX result = new CX(cx.length, index);
+        System.arraycopy(cx, 0, result.cx, 0, cx.length);
+        System.arraycopy(mps, 0, result.mps, 0, mps.length);
+        return result;
+    }
 }

Reply via email to