← Back to Pull requests

Raise TypeError when converting with incorrect matrix length for mode #10457

Closed
unknown closed this pull request without merging on Nov 08, 2026 11:42 UTC
View on GitHub
unknown unknown commented on Nov 07, 2026 16:27 UTC
Author

_convert_matrix_impl fills float m[12] with four values for a 4-sequence, but ImagingConvertMatrix reads all twelve when the target mode is RGB:

float v1 = m[4] * in[0] + m[5] * in[1] + m[6] * in[2] + m[7] + 0.5;
float v2 = m[8] * in[0] + m[9] * in[1] + m[10] * in[2] + m[11] + 0.5;

Nothing connects the length to the mode: Image.py checks the mode and not the length, the C layer checks the length and not the mode. So im.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 with matrix=(1, 0, 0, 0):

import sys
from PIL import Image
src = Image.new("RGB", (1, 1), (10, 20, 30))
print(f"argv tail {len(sys.argv) - 1:2}  ->  {src.convert('RGB', (1, 0, 0, 0)).getpixel((0, 0))}")

| result | runs |
|---|---:|
| (10, 0, 0) | 34 |
| (10, 255, 0) | 5 |
| (10, 12, 0) | 1 |

Red is 1 * 10 and stable; green is not. The 12 is neither clipping bound, so it comes from leftover floats rather than a saturated 0 or 255.

What this changes

Mode L reads only m[0:4], so it is unaffected by either length. Mode RGB now raises TypeError for a 4-value matrix instead of returning an image built from uninitialized memory.

Zero-initializing m is the other option: it keeps the call working, but would silently return an image with green and blue 0, so this raises instead.

Diff: 188 lines (+141 / -47) across 2 files Reviewer: radarhere Review duration: 1155m
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
0.36
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
0.17
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
60%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq
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
Reviewers
Assignees
Unassigned
Labels
risk: low confidence: 60.5% reviewed
Vouch Risk Breakdown
AI-powered review risk analysis
Change Risk
Change Risk · Model 1 (XGBoost)
Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
Score: 35.8% (MEDIUM) · Higher = larger blast radius
35.8%
Review Confidence
Review Confidence · Models 2 & 3
Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
Score: 60.5% · Lower = rushed or shallow review
60.5%
Residual Risk
Residual Risk · Core Equation
Residual = Change × (1 − Confidence)
Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
Score: 14.1% · Safe to merge
14.1%