Skip to content

fix: refuse a NUL in integer bounds and elements - #242

Merged
CaffeinatedCoder merged 2 commits into
mainfrom
fix/integer-trailing-nul
Oct 18, 2026
Merged

CaffeinatedCoder merged 2 commits into
mainfrom
fix/integer-trailing-nul

Conversation

@CaffeinatedCoder

Copy link
Copy Markdown
Owner

Closes #233

Problem

Integer bounds and elements accepted a trailing NUL, which PostgreSQL text can't hold:

  • Int32Range.ParseValue("31\0") returned 31.
  • Int16Set.Parse("{\"31\0\"}") returned {31}.
  • JSON range literals followed suit.

IntegerLiteral's fast path is the BCL TryParse with NumberStyles.Integer, which ignores trailing NULs. The #127 slow path already rejected 0x1F\0 and 1_0\0, and the decimal, float, temporal and Guid families reject a NUL. This is older than 10.0.0 and silent, and fixing it is a tightening, so it ships in this major.

Change

  • IntegerLiteral.Parse rejects U+0000 before either path. Every integer ParseValue goes through it, so every literal, set element, JSON value, TypeConverter call and EF bridge read is covered.
  • CHANGELOG 10.0.0 → Breaking: one entry.
  • docs/migration.md (v9.x): the NUL bullet and the "Keep NUL out of string elements" section now cover integer text too.

Tests

  • IntegerLiteralGrammarTests.ParseValue_RejectsANul covers 7 NUL rows (trailing, doubled, leading, inner, hex, separator) across all five integer ParseValues.
  • Literals_RejectANul covers a range, a multirange, a quoted and an unquoted set element, a JSON range, and a JSON set read with AllowReadingFromString.
  • With the check removed: the three trailing-NUL rows and Literals_RejectANul fail ("no exception was thrown"). The leading and inner NUL rows pass either way: those were already rejected, and they guard against a looser fix.
  • The live corpus can't hold this row: the PostgreSQL wire protocol can't carry a NUL in text, so there is no server answer to compare with.
  • Core 1353 passed, conventions 395 passed.

🤖 Generated with Claude Code

IntegerLiteral's fast path is the BCL TryParse with NumberStyles.Integer, which ignores trailing
NULs, so Int32Range.ParseValue("31\0") was 31, {"31\0"} was {31}, and JSON literals followed. The
#127 slow path always refused 0x1F\0 and 1_0\0, and the decimal, float, temporal and Guid families
refuse a NUL; PostgreSQL text cannot hold one. IntegerLiteral now refuses U+0000 before either path,
which every integer ParseValue, literal, JSON element and TypeConverter reaches. Older than 10.0.0,
silent, and a tightening, so it goes in the major's Breaking list.

IntegerLiteralGrammarTests: ParseValue_RejectsANul (five types × seven rows) and
Literals_RejectANul. With the check removed, the three trailing-NUL rows and the literal test fail;
a leading or inner NUL was already refused.

Closes #233

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 18, 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/literals Parse, TryParse and formatting package/core Affects CodoMetis.ValueRanges severity/low Cosmetic, message or documentation-level difference labels Oct 18, 2026
@CaffeinatedCoder

Copy link
Copy Markdown
Owner Author

Correction: the description says the decimal family already refused a NUL. It didn't. I based that on 1.5\0 being refused, which happened only because the precision check counted the NUL as a digit; 31\0 read as 31. Fixed in #270 (#251), together with the integer wrapper sets' JSON path.

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

Labels

area/literals Parse, TryParse and formatting 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.

Integer bounds and elements accept a trailing NUL

1 participant