Skip to content

fix(scanner): guard against out-of-range currency byte in scan frame - #1124

Merged
bmc08gt merged 1 commit into
code/cashfrom
fix/scanner-currency-index-oob
Jul 23, 2026
Merged

fix(scanner): guard against out-of-range currency byte in scan frame#1124
bmc08gt merged 1 commit into
code/cashfrom
fix/scanner-currency-index-oob

Conversation

@bmc08gt

@bmc08gt bmc08gt commented Jul 23, 2026

Copy link
Copy Markdown
Collaborator

Summary

Fixes a scanner crash (Bugsnag 6a5a4523e96556123eba0d68) — IndexOutOfBoundsException: Index 232 out of bounds for length 171, ~80 events / 3 users, live on production 2026.7.4.

A cash scan frame's byte 1 is an index into CurrencyCode. A foreign or corrupt Kik code can pass Reed–Solomon error-correction yet carry a currency byte outside that range, and PayloadKind.Payment.decode indexed CurrencyCode.entries (171 entries) with that untrusted 0–255 byte. A frame with byte[1] = 232 threw against the enum. Because the scanner decodes every camera frame, the exception stormed (~every 50 ms) and silently broke scanning for affected users.

Change

OpenCodePayload.fromList now short-circuits payment frames whose currency index is out of range to Empty (Unknown), which CodeScanDelegate ignores — no crash and no bogus grab attempt on non-Flipcash codes. Valid currencies (including the highest ordinal) are unaffected.

Testing

  • New regression test: fromList with byte[1] = 232 no longer throws and decodes to Unknown.
  • New boundary test: highest valid currency ordinal still decodes as Cash.
  • Full com.getcode.opencode.model.* suite green.

@github-actions github-actions Bot added type: fix Bug fix area: network gRPC, connectivity, API, exchange rates and removed type: fix Bug fix labels Jul 23, 2026
A foreign or corrupt Kik code can pass error-correction yet carry a
currency byte outside CurrencyCode's range. PayloadKind.Payment.decode
indexed CurrencyCode.entries with that untrusted 0-255 byte, so a frame
with byte[1] = 232 threw IndexOutOfBoundsException against the 171-entry
enum. Because the scanner decodes every camera frame, this stormed
Bugsnag (~every 50ms) and silently broke scanning for affected users.

PayloadKind.decode is now nullable: Payment.decode returns null when the
currency index is out of range instead of throwing, and
OpenCodePayload.fromList maps a null decode to Empty (Unknown), which the
scanner ignores — no crash and no bogus grab attempt. Adds regression +
boundary tests.

Bugsnag: 6a5a4523e96556123eba0d68

Signed-off-by: Brandon McAnsh <git@bmcreations.dev>
@bmc08gt
bmc08gt force-pushed the fix/scanner-currency-index-oob branch from 8c7a6f5 to 6bfe7c6 Compare July 23, 2026 17:21
@github-actions github-actions Bot added the type: fix Bug fix label Jul 23, 2026
@bmc08gt
bmc08gt merged commit b0f958d into code/cash Jul 23, 2026
3 checks passed
@bmc08gt
bmc08gt deleted the fix/scanner-currency-index-oob branch July 23, 2026 17:23
bmc08gt added a commit that referenced this pull request Jul 24, 2026
…1124)

A foreign or corrupt Kik code can pass error-correction yet carry a
currency byte outside CurrencyCode's range. PayloadKind.Payment.decode
indexed CurrencyCode.entries with that untrusted 0-255 byte, so a frame
with byte[1] = 232 threw IndexOutOfBoundsException against the 171-entry
enum. Because the scanner decodes every camera frame, this stormed
Bugsnag (~every 50ms) and silently broke scanning for affected users.

PayloadKind.decode is now nullable: Payment.decode returns null when the
currency index is out of range instead of throwing, and
OpenCodePayload.fromList maps a null decode to Empty (Unknown), which the
scanner ignores — no crash and no bogus grab attempt. Adds regression +
boundary tests.

Bugsnag: 6a5a4523e96556123eba0d68

Signed-off-by: Brandon McAnsh <git@bmcreations.dev>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: network gRPC, connectivity, API, exchange rates type: fix Bug fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant