Fix integer overflow in quirc_resize() dimension calculation #158
All Vouch review confidence checks passed
Residual risk 0.17 = Change Risk (0.40) × (1 − Review Confidence (0.57)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.40 · 291 lines diff across 3 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.340
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #158"
general
weight: 0.35
kaworu
Problem
In
quirc_resize(),w/h(andq->w/q->h) areint, so:evaluates
q->w q->handw hin signedintarithmetic first, then converts the (possibly overflowed) result tosize_t. For large-but-otherwise-valid dimensions whose product exceedsINT_MAX(2147483647), this overflows and produces a wrapped/garbage value, which then feeds thememcpy()length bound (min = (olddim < newdim ? olddim : newdim)) a few lines below.Reproduction
Built an unmodified copy of
lib/quirc.cand called, in sequence:Both individual dimension products overflow
intwhile each requested allocation (~2.4GB / ~3.4GB) is realistically satisfiable, so neither call is rejected bycalloc()'s own overflow-safe size check. The second call segfaults:confirmed with gdb: the crash is inside the
memcpy()atquirc.c:84, becauseolddim/newdimwrapped to a value wildly inconsistent with the real, correctly-sized buffers.Fix
Cast each operand to
size_tbefore multiplying, so the multiplication itself happens insize_tarithmetic (bothw/hare already validated non-negative a few lines above, so the cast is safe):This mirrors the approach taken in #103 for the similar overflow in
otsu().Testing
w*hwould have overflowedint.gcc -Wall -Wextraon the changed file introduces no new warnings compared to the pre-patch build.