GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Do not silently corrupt DECFLOAT values that do not fit the target format by fdcastel · Pull Request #1304 · FirebirdSQL/NETProvider

Conversation

@fdcastel

@fdcastel fdcastel commented Nov 7, 2026

Copy link
Copy Markdown
Member

Fixes #1298.

Summary

DecimalCodec.EncodeDecimal silently corrupted DECFLOAT values whose coefficient or exponent does not fit the target format; only a Debug.Assert checked it. The encoder now brings the value into the format's ranges without changing its numeric value, or throws OverflowException.

Changes

DecimalCodec.FitToFormat (used by EncodeFinite):

  • drops trailing zeros of a coefficient that has too many digits (12345678901234567890123456789012340 fits DECFLOAT(34)),
  • moves an exponent that is too large into the coefficient (1E384 becomes 1000000000000000E369 in DECFLOAT(16)),
  • drops trailing zeros when the exponent is too small (100E-400 becomes 1E-398),
  • clamps the exponent of zero,
  • throws OverflowException ("cannot be represented exactly as DECFLOAT(n)") when none of that is possible, i.e. when the value would have to be rounded, or overflows or underflows the format.

DecimalCodec is used by both the managed and the native client, so both are fixed.

Tests

  • DecimalCodecTests (NoServer) covers, for both formats:
    • representable values, including the format limits,
    • values that are representable only after normalization,
    • values that must throw.
  • FbDecFloat16SupportTests and FbDecFloat34SupportTests:
    • server round trip of normalizable values, which were corrupted before,
    • PassesUnrepresentableValueThrows, which also checks that the connection stays usable afterwards.
  • Without the fix, 35 of the new tests fail. With it, the embedded + NoServer suite passes: 648 passed, 0 failed.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@fdcastel
Do not silently corrupt DECFLOAT values that do not fit the target fo…
c1cf2d2
…rmat

DecimalCodec.EncodeDecimal wrote coefficients with more digits than the
format allows, and exponents outside its range, without any check (only a
Debug.Assert). In Release builds the excess bits overflowed into the
combination/exponent fields and the server stored a different value, e.g.:

  12345678901234567890123456789012345 -> DECFLOAT(34) stored 8345678901234567890123456789012345
  30000000000000004E-17               -> DECFLOAT(16) stored 0.08000000000000004
  1E400                               -> DECFLOAT(16) stored 8.000000000000001E-353

The encoder now brings the value into the format's ranges without changing
its numeric value (dropping trailing zeros of the coefficient, folding the
exponent into the coefficient, clamping the exponent of zero), and throws
OverflowException when the value cannot be represented exactly (too many
significant digits, exponent overflow or underflow). Values that previously
got corrupted although representable (e.g. 1E384 in DECFLOAT(16)) now work.
@fdcastel fdcastel mentioned this pull request Nov 7, 2026
Fix FbDecFloat explicit conversions from decimal, double and float #1306
Open
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

DECFLOAT values that do not fit DECFLOAT(16)/DECFLOAT(34) are silently corrupted

Uh oh!

There was an error while loading. Please reload this page.

1 participant

@fdcastel
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.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.