Skip to content

Fix OSS-Fuzz issues in FuzzHashKVs, FuzzGetBin, and FuzzSpanIDFromHex - #8996

Merged
pellared merged 3 commits into
open-telemetry:mainfrom
dashpole:fix-oss-fuzz-issues
Sep 23, 2026
Merged

pellared merged 3 commits into
open-telemetry:mainfrom
dashpole:fix-oss-fuzz-issues

Conversation

@dashpole

@dashpole dashpole commented Sep 22, 2026 •

Copy link
Copy Markdown
Contributor

Fix three issues reported by OSS-Fuzz in fuzz test harnesses. None of the fixes represent real issues.

  1. attribute.FuzzHashKVs (OSS-Fuzz 564808681 โ€” >60s Timeout)

    • Problem: FuzzHashKVs copies kvs into modifiedKvs and mutates modifiedKvs[0] to check for hash collisions via if h1 == h3 && !reflect.DeepEqual(kvs, modifiedKvs). However, several modifiedKvs[0] types and values were left unmodified by the switch statement:
      • FLOAT64 when f1 is NaN, ยฑInf (NaN + 1.0 is still NaN with identical bits, ยฑInf + 1.0 == ยฑInf), or a large float (|f1| >= 2^53, where f1 + 1.0 == f1).
      • BOOLSLICE, INT64SLICE, FLOAT64SLICE, STRINGSLICE, and BYTESLICE (omitted from the switch).
      • SLICE and MAP when empty (len == 0).
    • Why it timed out: Whenever modifiedKvs[0] was left unmodified (h1 == h3) and kvs also contained a Float64Slice with math.NaN() (which FuzzHashKVs unconditionally constructs when b has 0x7ff8... bytes), reflect.DeepEqual(kvs, modifiedKvs) returned false because reflect.DeepEqual(NaN, NaN) is always false in Go. This falsely triggered t.Logf("Potential hash collision detected: original=%v, modified=%v, hash=%d", kvs, modifiedKvs, h1). Under OSS-Fuzz's go-118-fuzz-build adapter, t.Logf unconditionally prints to stdout. After attribute: add String method for KeyValueย #8205 added KeyValue.String() (which serializes SliceValue and MapValue as JSON via appendJSONString), formatting both kvs and modifiedKvs with a 263 KB invalid-UTF-8 string s serialized 8 copies of s (~18 MB of \ufffd-escaped JSON) under -gcflags=all=-d=libfuzzer comparison instrumentation, taking ~150 seconds for a single input.
    • Fix: Ensure modifiedKvs[0] is mutated across all value types and edge cases (replacing non-finite floats with 0.0, using math.Nextafter when val + 1.0 == val, handling all primitive slice types, and mutating empty SLICE/MAP values), and avoid formatting the full kvs slices in t.Logf.
  2. sdk/metric/internal/aggregate.FuzzGetBin (OSS-Fuzz 458865858, Closes [Fuzzing] FuzzGetBin reports errorย #7576)

    • Problem: FuzzGetBin passed arbitrary float64 values directly to getBin(v). In production, expoHistogram.measure filters out ยฑInf and NaN before recording values, and lowerBound(bin, scale) loses precision in the subnormal float64 range (v < 0x1p-1022) where IEEE-754 subnormal numbers have fewer than 53 significand bits (e.g., 0x1p-1069 has only 5 bits of precision, causing lowerBound(getBin(0x1p-1069), 6) to round up to 0x1p-1069 and fail the lowerBound < v assertion).
    • Fix: Skip v < smallestNonZeroNormalFloat64 || math.IsInf(v, 0) || math.IsNaN(v) in FuzzGetBin.
  3. trace.FuzzSpanIDFromHex & trace.FuzzTraceIDFromHex (OSS-Fuzz 498709184)

    • Problem: validTraceIDRe := regexp.MustCompile(...) and validSpanIDRe := regexp.MustCompile(...) were placed inside FuzzTraceIDFromHex(f *testing.F) and FuzzSpanIDFromHex(f *testing.F) outside f.Fuzz(...). While standard go test -fuzz runs the outer Fuzz*(f) setup once per process, OSS-Fuzz's go-118-fuzz-build adapter (LLVMFuzzerTestOneInput -> LibFuzzerFuzzSpanIDFromHex) calls FuzzSpanIDFromHex(fuzzer) from the top on every single fuzz input. Re-parsing and compiling the regular expression on every iteration caused unnecessary heap allocation, GC churn, and SIGURG async preemption signal pressure in the Go c-archive + libFuzzer/ASAN runtime.
    • Fix: Hoist validTraceIDRe and validSpanIDRe to package-level variables so they are compiled once at package initialization.

Fix three issues reported by OSS-Fuzz in fuzz test harnesses:

1. `attribute.FuzzHashKVs` (OSS-Fuzztimeout):
   - Problem: `FuzzHashKVs` copies `kvs` to `modifiedKvs` and mutates `modifiedKvs[0]` to check for hash collisions (`h1 == h3 && !reflect.DeepEqual(kvs, modifiedKvs)`). However, several `modifiedKvs[0]` value types were either unhandled or left unmodified by the switch statement (e.g., `FLOAT64` when `NaN`, `ยฑInf`, or large values where `val + 1.0 == val`; `BOOLSLICE`, `INT64SLICE`, `FLOAT64SLICE`, `STRINGSLICE`, `BYTESLICE`; and empty `SLICE`/`MAP`). When `modifiedKvs[0]` went unmodified (`h1 == h3`) and `kvs` also contained a `Float64Slice` with `math.NaN()`, `!reflect.DeepEqual(kvs, modifiedKvs)` evaluated to `true` because `reflect.DeepEqual(NaN, NaN)` is `false` in Go.
   - Impact: Under OSS-Fuzz's `go-118-fuzz-build` adapter, `t.Logf` unconditionally prints to `stdout`. After open-telemetry#8205 added `KeyValue.String()` (which serializes `SliceValue`/`MapValue` via JSON), falsely triggering `t.Logf("Potential hash collision detected: original=%v, modified=%v...")` on a 263 KB invalid-UTF-8 string formatted 8 copies of the string (~18 MB of `\ufffd`-escaped JSON) under `-gcflags=all=-d=libfuzzer` instrumentation, taking ~150s for a single input and exceeding the 60s timeout.
   - Fix: Ensure `modifiedKvs[0]` is mutated across all value types and edge cases (replacing non-finite floats with `0.0`, using `math.Nextafter` when `val + 1.0 == val`, handling all slice types and empty `SLICE`/`MAP` values), and avoid formatting the full `kvs` slices in `t.Logf`.

2. `sdk/metric/internal/aggregate.FuzzGetBin` (Closes open-telemetry#7576):
   - Problem: `FuzzGetBin` passed arbitrary `float64` values directly to `getBin(v)`, whereas `expoHistogram.measure` filters out `ยฑInf` and `NaN` beforehand, and `lowerBound(bin, scale)` loses precision in the subnormal `float64` range (`v < 0x1p-1022`) where IEEE-754 floats have fewer than 53 significand bits (e.g. `lowerBound(getBin(0x1p-1069), 6)` rounds up to `0x1p-1069`, violating `lowerBound < v`).
   - Fix: Skip `v < smallestNonZeroNormalFloat64 || math.IsInf(v, 0) || math.IsNaN(v)` in `FuzzGetBin`.

3. `trace.FuzzSpanIDFromHex` and `trace.FuzzTraceIDFromHex`:
   - Problem: `regexp.MustCompile` was called inside `FuzzSpanIDFromHex(f *testing.F)` and `FuzzTraceIDFromHex(f *testing.F)` outside `f.Fuzz(...)`. While standard `go test -fuzz` executes the outer `Fuzz*(f)` setup once, OSS-Fuzz's `go-118-fuzz-build` wrapper invokes `Fuzz*(fuzzer)` from the top on every single fuzz iteration. Re-compiling the regular expressions on every input generated heavy heap allocation, GC churn, and `SIGURG` async preemption pressure in the Go `c-archive` + `libFuzzer`/`ASAN` runtime.
   - Fix: Hoist `validTraceIDRe` and `validSpanIDRe` to package-level variables so they are compiled once at package initialization.
@dashpole dashpole added the Skip Changelog PRs that do not require a CHANGELOG.md entry label Sep 22, 2026
@codecov

codecov Bot commented Sep 22, 2026 •

Copy link
Copy Markdown

Codecov Report

โœ… All modified and coverable lines are covered by tests.
โœ… Project coverage is 89.1%. Comparing base (34a9d1e) to head (6d02a34).

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##            main   #8996     +/-   ##
=======================================
- Coverage   89.1%   89.1%   -0.1%     
=======================================
  Files        338     338             
  Lines      22274   22274             
=======================================
- Hits       19859   19857      -2     
- Misses      2415    2417      +2     

see 3 files with indirect coverage changes

๐Ÿš€ New features to boost your workflow:
  • โ„๏ธ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@dashpole
dashpole marked this pull request as ready for review September 22, 2026 15:09
@dashpole

Copy link
Copy Markdown
Contributor Author

Fix for govulncheck: #8997

@pellared
pellared merged commit 96bd1b3 into open-telemetry:main Sep 23, 2026
49 checks passed
@pellared pellared added this to the v1.47.0 milestone Oct 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Skip Changelog PRs that do not require a CHANGELOG.md entry

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Fuzzing] FuzzGetBin reports error

4 participants