From 3f2f98336e4bf693ed047c75e3977ee8ab60bd95 Mon Sep 17 00:00:00 2001 From: Calixte Denizet Date: Wed, 3 Apr 2024 11:18:41 +0200 Subject: [PATCH] Update the current stride before composing when decoding a text region Fixes #17871. We do something similar to: https://source.chromium.org/chromium/chromium/src/+/main:third_party/pdfium/core/fxcodec/jbig2/JBig2_TrdProc.cpp;l=373-379;drc=24c6be6924df3ff585bb63f6aed4e2c81e791fb2 --- src/core/jbig2.js | 18 +++++++++++++++--- test/pdfs/.gitignore | 2 ++ test/pdfs/issue17871_bottom_right.pdf | Bin 0 -> 1133 bytes test/pdfs/issue17871_top_right.pdf | Bin 0 -> 1133 bytes test/test_manifest.json | 14 ++++++++++++++ 5 files changed, 31 insertions(+), 3 deletions(-) create mode 100755 test/pdfs/issue17871_bottom_right.pdf create mode 100755 test/pdfs/issue17871_top_right.pdf diff --git a/src/core/jbig2.js b/src/core/jbig2.js index e360ce015..402e30b7e 100644 --- a/src/core/jbig2.js +++ b/src/core/jbig2.js @@ -865,6 +865,20 @@ function decodeTextRegion( decodingContext ); } + + let increment = 0; + if (!transposed) { + if (referenceCorner > 1) { + currentS += symbolWidth - 1; + } else { + increment = symbolWidth - 1; + } + } else if (!(referenceCorner & 1)) { + currentS += symbolHeight - 1; + } else { + increment = symbolHeight - 1; + } + const offsetT = t - (referenceCorner & 1 ? 0 : symbolHeight - 1); const offsetS = currentS - (referenceCorner & 2 ? symbolWidth - 1 : 0); let s2, t2, symbolRow; @@ -896,7 +910,6 @@ function decodeTextRegion( ); } } - currentS += symbolHeight - 1; } else { for (t2 = 0; t2 < symbolHeight; t2++) { row = bitmap[offsetT + t2]; @@ -921,7 +934,6 @@ function decodeTextRegion( ); } } - currentS += symbolWidth - 1; } i++; const deltaS = huffman @@ -930,7 +942,7 @@ function decodeTextRegion( if (deltaS === null) { break; // OOB } - currentS += deltaS + dsOffset; + currentS += increment + deltaS + dsOffset; } while (true); } return bitmap; diff --git a/test/pdfs/.gitignore b/test/pdfs/.gitignore index 87a32129f..b3649ac87 100644 --- a/test/pdfs/.gitignore +++ b/test/pdfs/.gitignore @@ -637,3 +637,5 @@ !issue17730.pdf !bug1883609.pdf !issue17808.pdf +!issue17871_bottom_right.pdf +!issue17871_top_right.pdf diff --git a/test/pdfs/issue17871_bottom_right.pdf b/test/pdfs/issue17871_bottom_right.pdf new file mode 100755 index 0000000000000000000000000000000000000000..89f216be28f266faf497cfa0f947a41cd1c892ce GIT binary patch literal 1133 zcmY!laBnwZN4vLECQ zpc}w+axNFhM3;O}*g)05LJ4FI!k19Pj4jPTE`@|N)O8?%;L@ZLaOivH0>d065}ug? zv>a$5h~tr(nVwMsvKGX1&dN1%&yUUQ5n9!}{??^2gZ+ckg6>7P*qK^NmAg_;ioR>q5SBP2TO8 z!)||e%}nl_U(#9KW6z}S=eB!LWoJ;hNM3&RG2SoF@91W2d+c!RNyq=XS5vJI*(mPn|1!u``-yeGT zp-XUXh~@OCqBzF(+iy)7-G~Ovbl+0<0mb_vE%(e?8Fkto)?mrU(3IFU?T< zT($f^(7#OV3XGtTP(u$V1|AJiaP;1D`F>xUJ^Sg`z6R1dRVT~mjRTQPBaTzF>aT&mYf|;qQv6(`e0$j`xm~25nArB#DW`QAQXbj9(XzGkC zFx45GA*tgkDN4-DNiBjF62X~OsX*5N6I)PzJ}@N#Q#rVBC@x7XDgisz(!`WYRn^ts GjSB$WRZ-6X literal 0 HcmV?d00001 diff --git a/test/pdfs/issue17871_top_right.pdf b/test/pdfs/issue17871_top_right.pdf new file mode 100755 index 0000000000000000000000000000000000000000..22ef5a9d48f3166d0eea0958718726f66e7a6f35 GIT binary patch literal 1133 zcmY!laBnwZN4vLECQ zpc}w+axNFhM3;O}*g)05LJ4FI!k19Pj4jPTE`@|N)O8?%;L@ZLaOivH0>d065}ug? zv>a$5h~tr(nVwMsvKGX1&dN1%&yUUQ5n9!}{??^2gZ+ckg6>7P*qK^NmAg_;ioR>q5SBP2TO8 z!)||e%}nl_U(#9KW6z}S=eB!LWoJ;hNM3&RG2SoF@91W2d+c!RNyq=XS5vJI*(mPn|1!u``-yeGT zp-XUXh~@OCqBzF(+iy)7-G~Ovbl+0<0mb_vE%(e?8Fkto)?mrU(3IFU?T< zT($f^(7#OV3XGtTP(u$V1|ADgaP;1DoqXW;V&CoEh8&gkARWx=;4qX$*T4i1$~BB2 zbu5OEu*Q;%DvDCmxC|7`xD4Px!OYau*i0c!0WM|;Otv7PkcSX6v%nBDGzR7?G<8N6 znCgtpkkoON6eVWnq!vL7iQvqtRG@2si7hBUADEJWsT^E56qh6xm4F>