Skip to content

Fix: grid sampler bounds checking#82

Open
bashhack wants to merge 1 commit intomakiuchi-d:masterfrom
bashhack:fix/grid-sampler-bounds
Open

Fix: grid sampler bounds checking#82
bashhack wants to merge 1 commit intomakiuchi-d:masterfrom
bashhack:fix/grid-sampler-bounds

Conversation

@bashhack
Copy link
Copy Markdown
Contributor

Summary

  • Fix transcription error from Java ZXing where y == height was nudged to float64(height) instead of float64(height - 1)
  • Add explicit math.IsNaN / math.IsInf rejection for Go 1.24+ where int(math.NaN()) changed from MinInt64 to 0, silently bypassing bounds checks
  • Rewrite checkAndNudgePoints from a two-pass endpoint-only check to a single pass over all points, clamping moderate overshoot (within 5% of image dimension) instead of rejecting it
  • Remove redundant px >= width || py >= height check in DefaultGridSampler.SampleGridWithTransform because BitMatrix.Get already returns false for out of bounds coordinates

Context

Perspective transforms may expectedly overshoot image edges by a few pixels. The old implementation rejected these outright, causing NotFoundException on valid QR codes. This proposed implementation clamps small overshoot to the nearest edge while still rejecting degenerate transforms (NaN, Inf, or far out of bounds).

Testing

[x] All existing test packages pass
[x] New tests added for NaN/Inf, clamping behavior, far-out-of-bounds rejection and interior points checking

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant