Repository navigation
fix: unify the exceptions for content that does not fit and bad sizes - #511
Merged
Merged
Conversation
Standard QR threw InvalidOperationException for content past version 40, while Micro QR and rMQR threw ArgumentException. All three now throw ArgumentException. Its ParamName is "options" when a version, a range or an rMQR height narrowed the versions, and null when nothing did. Micro QR and rMQR no longer report the removed "requestedVersion" parameter. The Standard QR message now says how much version 40 holds. The decoders' matrix overloads reported a non-positive size as a buffer too small. They now throw ArgumentOutOfRangeException naming the size, as the image overloads do, and GetMaxDecodedLength words an undefined version the same way in all three. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The URI buffer was sized at three characters per character of text, so 400 million characters of valid data rented 2,400 MB before any check. Past 715,827,882 characters the size overflowed int, went negative and picked the 512-character stack buffer. The text does not bound the URI, since an AI repeated with one value is written once. The buffer now stops one character past the symbol's capacity: 7,090 for Standard QR and 362 for rMQR, which always fits the stack. A URI that fills it fits no symbol, so the Create forms throw ArgumentException with no ParamName after the options are checked, and the size forms return false. The builder checks the data before it writes, so a data error is still reported first. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
An undefined RmQRVersion reported ParamName "requestedVersion", the name of a parameter removed in 1.x. It now reports "version", the option member, as an undefined height or fit strategy reports its own. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The exceptions for "content does not fit" and for invalid sizes consistent across the three symbologies. It also caps the GS1 Digital Link URI buffer, which could rent gigabytes and overflow
inton very long input.Intent
InvalidOperationExceptionfor content past version 40, while Micro QR and rMQR threwArgumentException.ParamName: some errors still namedrequestedVersion, a parameter removed in 1.x.Before / After
InvalidOperationExceptionArgumentException,ParamNamenulloptions, Micro QR / rMQRrequestedVersionornullArgumentException,ParamNameoptionsin all threeRmQRVersionParamNamerequestedVersionParamNameversion, likeheightandfitStrategyTryDecodewith size ≤ 0ArgumentException"Module buffer too small: required 9"ArgumentOutOfRangeExceptionnamingsize(width/heightfor rMQR), as the image overloads already didGetMaxDecodedLengthwith an undefined versionintand picks the 512-character stack bufferThe QR overflow message now says how much version 40 holds, in the same style as Micro QR and rMQR:
Changes
QRCodeGenerator: the default, FNC1 and Optimal paths now share oneContentTooLonghelper. It finds the version 40 maximum by bisection, on the failure path only, so the success path does no extra work. The maximums match the standard capacity table, including the UTF-8 BOM case.MicroQRCodeGeneratorandRmQRVersionSelector: errors for a version, range or height set in options nameoptions. An undefined rMQR version namesversion.modules. The XML docs list the new exception.UriBufferLengthcomputes inlongand caps at the symbol's capacity + 1. The buffer is sliced to that exact length.ArgumentExceptionwith noParamName, after the options are checked. The size forms returnfalse.InvalidOperationException.ErrorContractTestmeasures each case through the text, byte and destination overloads of all three symbologies.migration.mdnotes the behavior changes. The specs (qrcode-symbologies.md,standardqr-encoder.md,qrcode-gs1-data.md) record the decisions and measurements.Breaking changes
InvalidOperationExceptionfor Standard QR content past version 40 must catchArgumentException, or callTryGetRequiredBufferSizefirst.ParamNamerequestedVersionfrom Micro QR or rMQR errors now seesoptionsorversion.ArgumentOutOfRangeExceptionderives fromArgumentException, so existingcatch (ArgumentException)blocks around the matrix decoders still work.🤖 Generated with Claude Code