Raise TypeError when converting with incorrect matrix length for mode #10457
All Vouch review confidence checks passed
Residual risk 0.14 = Change Risk (0.36) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.36 · 188 lines diff across 2 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.314
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #10457"
general
weight: 0.35
radarhere
_convert_matrix_implfillsfloat m[12]with four values for a 4-sequence, butImagingConvertMatrixreads all twelve when the target mode isRGB:Nothing connects the length to the mode:
Image.pychecks the mode and not the length, the C layer checks the length and not the mode. Soim.convert("RGB", (a, b, c, d))passes both, and green and blue are computed from eight elements that were never written.40 runs of the same following script (Pillow 13.0.0, CPython 3.13, macOS arm64), converting a 1x1
(10, 20, 30)pixel withmatrix=(1, 0, 0, 0):| result | runs |
|---|---:|
|
(10, 0, 0)| 34 ||
(10, 255, 0)| 5 ||
(10, 12, 0)| 1 |Red is
1 * 10and stable; green is not. The12is neither clipping bound, so it comes from leftover floats rather than a saturated 0 or 255.What this changes
Mode
Lreads onlym[0:4], so it is unaffected by either length. ModeRGBnow raisesTypeErrorfor a 4-value matrix instead of returning an image built from uninitialized memory.Zero-initializing
mis the other option: it keeps the call working, but would silently return an image with green and blue 0, so this raises instead.