Skip to content

fix: refuse a NUL in decimal text and in the integer wrapper sets' JSON - #270

Merged
CaffeinatedCoder merged 2 commits into
mainfrom
fix/numeric-nul
Oct 19, 2026
Merged

CaffeinatedCoder merged 2 commits into
mainfrom
fix/numeric-nul

Conversation

@CaffeinatedCoder

Copy link
Copy Markdown
Owner

Closes #251

Problem

#233 (PR #242) rejected a NUL in integer text, but two siblings still read 31\0 as 31. PostgreSQL text can't hold U+0000.

  1. The decimal family. DecimalLiteral used decimal.Parse with NumberStyles.Float, and BigInteger.Parse in Represents. Both ignore trailing NULs. So DecimalRange, its multirange, DecimalSet and DecimalSet<T> read 31\0 and 1e2\0 through every entry point. 1.5\0 was rejected only because the precision check counted the NUL as a digit. fix: refuse a NUL in integer bounds and elements #242's description said the decimal family already rejected a NUL. I had based that on 1.5\0, and it was wrong.
  2. The integer wrapper sets' JSON. ReadIntegerText, the quoted-number path, ran long.TryParse and then re-formatted the number. So Int16Set<T>, Int32Set<T> and Int64Set<T> read ["31\u0000"] under AllowReadingFromString, where the plain sets throw.

Change

  • DecimalLiteral.Parse rejects U+0000 first, with a message that names the rule.

  • ValueSetElementJson.ReadIntegerText rejects a NUL before long.TryParse.

  • Swept the other numeric readers:

    • The float families validate their own grammar first and already reject a NUL.
    • The decimal JSON path hands the raw text on to DecimalLiteral, so it needs no check of its own.
    • A wrapper element that formats with a NUL is rejected when the set is built, so the write-side checks need none.

    I added a check only where removing it fails a test.

  • CHANGELOG 10.0.0 → Breaking: the NUL line now names DecimalRange and DecimalSet. The migration guide's NUL bullet and section say "integer or decimal".

Tests

  • New NumericNulTests:
    • the decimal family through ParseValue (range, set, wrapper), the literals (range, DecimalRange.Finite, multirange, set, wrapper set) and JSON;
    • the integer families' JSON, plain and wrapper sets and a range;
    • the float families, kept as they are.
  • Fixes removed one at a time: with the decimal check removed, 3 rows fail (31\0, 1e2\0, 31\0\0). With the integer JSON check removed, 2 rows fail. 1.5\0 passes either way, rejected by the precision check as before.
  • Seeds: parser-reads-the-current-culture.patch touches the same DecimalLiteral lines. It is refreshed and still CAUGHT by both culture oracles (4 of 61).
  • Core 1382, conventions 399, EF unit 285, ASP.NET Core 92: all passed.

🤖 Generated with Claude Code

#233 refused a NUL in integer text, but two siblings still read "31\0" as 31 (#251). DecimalLiteral
went through decimal.Parse with NumberStyles.Float (and BigInteger.Parse in Represents), which ignore
trailing NULs, so DecimalRange, its multirange, DecimalSet and DecimalSet<T> read it in every entry
point; "1.5\0" was refused only because the precision check counted the NUL as a digit. And
ReadIntegerText, the quoted-number path of the integer wrapper sets' JSON, ran long.TryParse and
re-formatted the number, so Int16Set<T>, Int32Set<T> and Int64Set<T> read ["31\u0000"] under
AllowReadingFromString where the plain sets throw. Both now refuse U+0000. Swept: the float families
validate their own grammar and refuse it; the decimal JSON path hands the raw text to DecimalLiteral;
a wrapper element formatting with a NUL is refused when the set is built.

NumericNulTests: the decimal family through ParseValue, literals, the Finite shape and JSON; the
integer families' JSON, plain and wrapper; the float families held as they are. With the decimal check
removed 3 rows fail, with the integer JSON check removed 2. The changelog's NUL line and the migration
guide name the decimal family. parser-reads-the-current-culture.patch is refreshed against the new
DecimalLiteral and still CAUGHT.

Closes #251

Found-By: CA
Defect-Class: LIT

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@CaffeinatedCoder CaffeinatedCoder added this to the 10.0.0 milestone Oct 19, 2026
@CaffeinatedCoder CaffeinatedCoder added bug Something isn't working silent Answers wrongly without throwing — fixes go in the next major, never deferred breaking Changes an answer or a signature — needs a major area/value-sets Value set families and wrapper arities area/json System.Text.Json and TypeConverter wire forms area/literals Parse, TryParse and formatting package/core Affects CodoMetis.ValueRanges severity/low Cosmetic, message or documentation-level difference labels Oct 19, 2026
@CaffeinatedCoder
CaffeinatedCoder merged commit 4fee9df into main Oct 19, 2026
@CaffeinatedCoder
CaffeinatedCoder deleted the fix/numeric-nul branch October 19, 2026 05:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/json System.Text.Json and TypeConverter wire forms area/literals Parse, TryParse and formatting area/value-sets Value set families and wrapper arities breaking Changes an answer or a signature — needs a major bug Something isn't working package/core Affects CodoMetis.ValueRanges severity/low Cosmetic, message or documentation-level difference silent Answers wrongly without throwing — fixes go in the next major, never deferred

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Decimal text and the integer wrapper sets' JSON still read a trailing NUL

1 participant