The previous patch_jpegdec.py used in-place string replacement with a single shared marker for two distinct DC writes (main store and successive-approximation update). If only one of the two anchors matched, the file was written half-patched and the shared marker locked the partial state in for every subsequent run. Generate the fixes as `git format-patch` artifacts under scripts/jpegdec_patches/, then apply them in lexical order via `git apply`. Idempotency is decided by git itself: `--check --reverse` succeeds means already applied; `--check` succeeds means appliable; neither aborts the build rather than leaving a half-patched file. No behaviour change to the patched JPEGDEC source: same redirect, same DC guards, same intent. Just stops the pre-build script from doing something it has no business doing.
42 lines
1.7 KiB
Diff
42 lines
1.7 KiB
Diff
From f6238b54c2de34c8e29b0d371a7e902d9cf579bf Mon Sep 17 00:00:00 2001
|
|
From: patch <patch@local>
|
|
Date: Mon, 18 May 2026 20:58:22 -0700
|
|
Subject: [PATCH 2/2] Guard pMCU[0] DC writes against MCU_SKIP
|
|
|
|
---
|
|
src/jpeg.inl | 11 +++++++++--
|
|
1 file changed, 9 insertions(+), 2 deletions(-)
|
|
|
|
diff --git a/src/jpeg.inl b/src/jpeg.inl
|
|
index 26bcf6f..1bd38b2 100644
|
|
--- a/src/jpeg.inl
|
|
+++ b/src/jpeg.inl
|
|
@@ -1855,7 +1855,11 @@ static int JPEGDecodeMCU_P(JPEGIMAGE *pJPEG, int iMCU, int *iDCPredictor)
|
|
{
|
|
// (*iDCPredictor) |= iPositive; // in case the scan is run more than once
|
|
// pMCU[0] = *iDCPredictor; // store in MCU[0]
|
|
- pMCU[0] |= iPositive;
|
|
+ // CrossPoint patch: guard against MCU_SKIP. The pMCU
|
|
+ // redirect makes &sMCUs[0] safe to dereference, but
|
|
+ // writing here would clobber the just-decoded Y DC.
|
|
+ if (iMCU >= 0)
|
|
+ pMCU[0] |= iPositive;
|
|
}
|
|
goto mcu_done; // that's it
|
|
}
|
|
@@ -1887,7 +1891,10 @@ static int JPEGDecodeMCU_P(JPEGIMAGE *pJPEG, int iMCU, int *iDCPredictor)
|
|
ulCode <<= pJPEG->cApproxBitsLow; // successive approximation shift value
|
|
(*iDCPredictor) += ulCode;
|
|
}
|
|
- pMCU[0] = (short)*iDCPredictor; // store in MCU[0]
|
|
+ // CrossPoint patch: guard against MCU_SKIP. See note on the
|
|
+ // matching SA write above.
|
|
+ if (iMCU >= 0)
|
|
+ pMCU[0] = (short)*iDCPredictor; // store in MCU[0]
|
|
}
|
|
// Now get the other 63 AC coefficients
|
|
pFast = &pJPEG->usHuffAC[pJPEG->ucACTable * HUFF11SIZE];
|
|
--
|
|
2.50.1 (Apple Git-155)
|
|
|