Skip to content

fix: Silence UBSan diagnostics in the ubsan build config#7531

Open
pratikmankawde wants to merge 8 commits into
developfrom
pratik/ubsan-suppression-cleanup
Open

fix: Silence UBSan diagnostics in the ubsan build config#7531
pratikmankawde wants to merge 8 commits into
developfrom
pratik/ubsan-suppression-cleanup

Conversation

@pratikmankawde

@pratikmankawde pratikmankawde commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

High Level Overview of Change

The debian-trixie-clang-22-amd64-debug-ubsan job logs many non-fatal UBSan runtime error: lines. The job already passes (UBSan runs with halt_on_error=false); this PR silences the noise. Three changes: move the workflow's sanitizer-options step earlier so suppressions apply to instrumented dependency tools, extend ubsan.supp, and fix one genuine divide-by-zero in code.

Context of Change

This is a CI/build-config cleanup, not a behavior change.

Why existing suppressions didn't catch these. The build uses -fsanitize=undefined,float-divide-by-zero,unsigned-integer-overflow. The latter two are separate checks, not part of the undefined group (unsigned wraparound and IEEE divide-by-zero are well-defined, not UB). So an undefined:<x> suppression does not silence them — each needs its own check-name key. This is why undefined:protobuf left protobuf's unsigned-integer-overflow leaks unsuppressed.

Build-time fix (workflow). The protocol code-gen and build steps run instrumented dependency tools (protoc, grpc) before the Set sanitizer options step exported UBSAN_OPTIONS, so the suppression list never applied to them. The step is moved to run right after Configure CMake — before code-gen and build — reusing the existing ${GITHUB_WORKSPACE}$GITHUB_ENV mechanism so the path resolves correctly inside the container job.

Test-time fix (ubsan.supp). Broad unsigned-integer-overflow keys for absl and protobuf (matching the existing boost handling), a few libstdc++ headers, and entries for rippled's intentional wraparound (hashing, PRNG, guarded counters) and test arithmetic. Own-code entries are keyed by source file: this UBSan build runs without symbol info, so the runtime reports only file:line, not the enclosing function — function-name globs never matched.

Code fix. A diagnostic JLOG line in doLedgerGrpc divided the extract time by the object / transaction counts, which are zero for an empty ledger (float-divide-by-zero). The per-item rates are now guarded.

API Impact

  • Public API: New feature (new methods and/or new fields)
  • Public API: Breaking change (in general, breaking changes should only impact the next api_version)
  • libxrpl change (any change that may affect libxrpl or dependents of libxrpl)
  • Peer protocol change (must be backward compatible or bump the peer protocol version)

Test Plan

  • CI …-ubsan job: confirm zero runtime error: lines in both the build and the embedded-test steps.
  • Pre-commit hooks (clang-format, clang-tidy, cspell, workflow formatting) pass locally.

The debian-trixie-clang-22-amd64-debug-ubsan job logs many non-fatal
UBSan `runtime error:` lines (it passes because halt_on_error=false).
These come from two places that needed different fixes.

Build-time: the protocol code-gen and build steps run instrumented
dependency tools (protoc, grpc) before the "Set sanitizer options" step
exported UBSAN_OPTIONS, so the suppression list never applied to them.
Move that step to run right after "Configure CMake" — before code-gen
and build — reusing the existing ${GITHUB_WORKSPACE}/$GITHUB_ENV
mechanism so the path resolves correctly inside the container job.

Test-time: extend ubsan.supp. unsigned-integer-overflow and
float-divide-by-zero are separate checks, not part of the `undefined`
group, so undefined:<x> keys do not cover them. Add broad
unsigned-integer-overflow keys for absl and protobuf (matching the
existing boost handling), a few libstdc++ headers, and narrowly
function-scoped entries for rippled's intentional wraparound (hashing,
PRNG, counters guarded by explicit overflow checks) plus test
arithmetic, each with a rationale comment.

Fix the one genuine issue in code: a diagnostic JLOG line in
doLedgerGrpc divided the extract time by the object / transaction
counts, which are zero for an empty ledger. Guard the per-item rates.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@pratikmankawde pratikmankawde added the DraftRunCI Normally CI does not run on draft PRs. This opts in. label Jun 11, 2026
pratikmankawde and others added 2 commits June 11, 2026 16:50
The function-name suppressions for rippled's own code never matched: this
UBSan build runs without symbol information, so the runtime only reports
the file:line of each diagnostic, not the enclosing function. The CI log
still showed ~486 unsuppressed `runtime error:` lines, all from own-code
files whose entries were written as function-name globs.

Re-key every rippled own-code entry by source file (the only granularity
the runtime can match here), covering all files flagged by the ubsan job:
amount/number arithmetic, hashing and PRNG, counter/sentinel wraparound
guarded by explicit checks, codec index math, and intentional test
arithmetic. Each entry keeps a comment naming the construct.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@codecov

codecov Bot commented Jun 11, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 82.0%. Comparing base (cee1574) to head (fd2355f).
⚠️ Report is 2 commits behind head on develop.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##           develop   #7531   +/-   ##
=======================================
  Coverage     82.0%   82.0%           
=======================================
  Files         1009    1009           
  Lines        76779   76780    +1     
  Branches      8937    8937           
=======================================
+ Hits         62980   62982    +2     
+ Misses       13790   13789    -1     
  Partials         9       9           
Files with missing lines Coverage Δ
src/xrpld/rpc/handlers/ledger/Ledger.cpp 48.9% <100.0%> (ø)

... and 2 files with indirect coverage changes

Impacted file tree graph

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@pratikmankawde pratikmankawde changed the title ci: Silence UBSan diagnostics in the ubsan build config fix: Silence UBSan diagnostics in the ubsan build config Jun 11, 2026
@pratikmankawde pratikmankawde removed the DraftRunCI Normally CI does not run on draft PRs. This opts in. label Jun 11, 2026
@pratikmankawde pratikmankawde marked this pull request as ready for review June 11, 2026 16:47

@mathbunnyru mathbunnyru left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we make halt_on_error=True?

If I understand correctly, right now even if there is an error, unless someone notices it in logs, in won't crash anything and tests will still tell "passed"?

Comment thread .github/workflows/reusable-build-test-config.yml Outdated
@pratikmankawde

Copy link
Copy Markdown
Contributor Author

Can we make halt_on_error=True?

If I understand correctly, right now even if there is an error, unless someone notices it in logs, in won't crash anything and tests will still tell "passed"?

The current state of the code is not clean enough to allow halt_on_error to be set to true. We are slowly fixing it.

pratikmankawde and others added 2 commits June 11, 2026 18:28
Address review feedback: the Set sanitizer options step repeated
${GITHUB_WORKSPACE}/sanitizers/suppressions/ for every sanitizer.
Extract it into a SUPP shell variable for readability. No behavior change.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

@xrplf-ai-reviewer xrplf-ai-reviewer Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues.

Review by Claude Sonnet 4.6 · Prompt: V15

Now that every UBSan diagnostic in the build and test phases is either
fixed or suppressed, flip halt_on_error to true so any new undefined
behavior fails the job instead of being logged and ignored.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

@xrplf-ai-reviewer xrplf-ai-reviewer Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clean changes

Review by Claude Sonnet 4.6 · Prompt: V15

@mathbunnyru

Copy link
Copy Markdown
Contributor

Can we make halt_on_error=True?
If I understand correctly, right now even if there is an error, unless someone notices it in logs, in won't crash anything and tests will still tell "passed"?

The current state of the code is not clean enough to allow halt_on_error to be set to true. We are slowly fixing it.

Seems to work now 🎉
Could you please introduce an UB to just check that it actually catches problems? (and then revert it)

@pratikmankawde

pratikmankawde commented Jun 11, 2026

Copy link
Copy Markdown
Contributor Author

Can we make halt_on_error=True?
If I understand correctly, right now even if there is an error, unless someone notices it in logs, in won't crash anything and tests will still tell "passed"?

The current state of the code is not clean enough to allow halt_on_error to be set to true. We are slowly fixing it.

Seems to work now 🎉 Could you please introduce an UB to just check that it actually catches problems? (and then revert it)

Already done earlier when runs were failing and I had to set this to false.

@pratikmankawde pratikmankawde added the Ready to merge *PR author* thinks it's ready to merge. Has passed code review. Perf sign-off may still be required. label Jun 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Ready to merge *PR author* thinks it's ready to merge. Has passed code review. Perf sign-off may still be required.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants