Skip to content

[DICOM] Remove Int64 overflow path in length-matched crypto hash output - #266

Draft
Josiah Vinson (jovinson-ms) with Copilot wants to merge 4 commits into
masterfrom
copilot/prevent-overflow-crypto-hash
Draft

[DICOM] Remove Int64 overflow path in length-matched crypto hash output#266
Josiah Vinson (jovinson-ms) with Copilot wants to merge 4 commits into
masterfrom
copilot/prevent-overflow-crypto-hash

Conversation

Copilot AI commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

MatchInputStringLength=true could throw OverflowException for numeric inputs with 19+ digits because the length-preserving path depended on Int64 bounds. This change removes that failure mode while keeping deterministic, numeric-only, exact-length output behavior.

  • Length-preserving hash generation

    • Reworked GenerateOutputOfSameLength to avoid Int64-bounded range construction for long inputs.
    • Kept existing behavior for shorter inputs (<=18 digits) where practical.
    • Added a deterministic BigInteger-based mapping for longer lengths (>18) to preserve fixed-length numeric output without overflow.
  • Deterministic long-length expansion

    • Added deterministic hash-byte expansion for large numeric ranges and mapped into the valid digit-space range.
    • Documented the entropy expansion choice and modulo-range mapping behavior in code.
  • Boundary coverage for regression

    • Added/updated unit coverage for 1-, 18-, 19-, and longer-character inputs (40 chars).
    • Assertions focus on: same-length output, numeric-only output, and determinism for identical input/key.
// Long-length path no longer parses "999...9" into Int64.
BigInteger lowerBound = BigInteger.Pow(10, input.Length - 1);
BigInteger range = lowerBound * 9;
byte[] expandedHash = ExpandHash(hash, requiredBytes);
BigInteger value = new BigInteger(expandedHash, isUnsigned: true, isBigEndian: true);

return (lowerBound + (value % range)).ToString(CultureInfo.InvariantCulture);

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

Copilot AI and others added 3 commits August 13, 2026 19:40
Co-authored-by: jovinson-ms <88204686+jovinson-ms@users.noreply.github.com>
Co-authored-by: jovinson-ms <88204686+jovinson-ms@users.noreply.github.com>
Co-authored-by: jovinson-ms <88204686+jovinson-ms@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix overflow exception in crypto hash output length [DICOM] Remove Int64 overflow path in length-matched crypto hash output Aug 13, 2026
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.

[DICOM] Prevent overflow when matching crypto hash output length

2 participants