Skip to content

fix(datamatrix): return an error instead of panicking past 144x144 capacity - #108

Closed
kihyun1998 wants to merge 1 commit into
rxing-core:mainfrom
kihyun1998:fix/106-datamatrix-oversize-panic
Closed

kihyun1998 wants to merge 1 commit into
rxing-core:mainfrom
kihyun1998:fix/106-datamatrix-oversize-panic

Conversation

@kihyun1998

Copy link
Copy Markdown

Fixes #106

Summary

 EncoderContext
-  pub fn updateSymbolInfo(&mut self)
-  pub fn updateSymbolInfoWithLength(&mut self, len: usize)
-    symbol_lookup.lookup_with_codewords_shape_size_fail(.., true).unwrap().unwrap()
+  pub fn updateSymbolInfo(&mut self) -> Result<()>
+  pub fn updateSymbolInfoWithLength(&mut self, len: usize) -> Result<()>
+    symbol_lookup.lookup_with_codewords_shape_size_fail(.., true)?

Every caller (ascii/base256/c40/edifact/x12 encoders, high_level_encoder) already returns Result<()>, so they just add ?. The error is the lookup's own IllegalArgumentException, the same as ZXing (SymbolInfo.lookup throws IllegalArgumentException) and as the DataMatrixCompact path already returns today.

Evidence

tests/github_issues.rs::issue_106_datamatrix_oversize, at the boundaries from the issue:

"x" * 2335, "9" * 3116  -> Ok, 144x144
"x" * 2336, "9" * 3117  -> Err(IllegalArgumentException)
  • Before: panicked at src/datamatrix/encoder/encoder_context.rs:172:22
    After: passes

Also checked against the fix (no panic anywhere, all IllegalArgumentException): FORCE_RECTANGLE with 300 chars, MaxSize 10x10 with 100 chars, 4000-char inputs. cargo fmt --check, and the CI commands (check, build, test with and without default features, workspace, release) all pass.

Merge Danger

Door: two-way until released

EncoderContext is publicly re-exported from datamatrix::encoder, so both methods change signature (() -> Result<()>). An external caller that ignores the return value still compiles, with an unused_must_use warning; one that binds the () result would not. If you'd rather keep the old signatures for 0.9.4, I can add fallible variants instead.

Blast Radius: DataMatrix encoding

Only the oversize path changes behaviour (panic -> Err); inputs that fit encode as before.

🤖 Generated with Claude Code

…pacity

EncoderContext::updateSymbolInfo and updateSymbolInfoWithLength unwrapped
the symbol lookup, so encoding data that does not fit the largest symbol
(or the MaxSize hint) panicked. Both now return Result<()> and propagate
the lookup's IllegalArgumentException, matching ZXing's
IllegalArgumentException and the compact (minimal encoder) path.

Fixes rxing-core#106

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

DataMatrix writer panics instead of returning an error when data exceeds 144x144 capacity

1 participant