Repository navigation
Fix OSS-Fuzz issues in FuzzHashKVs, FuzzGetBin, and FuzzSpanIDFromHex - #8996
Merged
Merged
Conversation
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.
Codecov Reportโ
All modified and coverable lines are covered by tests. Additional details and impacted files@@ 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 ๐ New features to boost your workflow:
|
dashpole
marked this pull request as ready for review
September 22, 2026 15:09
dashpole
requested review from
MrAlias,
XSAM,
dmathieu,
flc1125 and
pellared
as code owners
September 22, 2026 15:09
Contributor
Author
|
Fix for govulncheck: #8997 |
MrAlias
approved these changes
Sep 22, 2026
pellared
approved these changes
Sep 22, 2026
dmathieu
approved these changes
Sep 23, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fix three issues reported by OSS-Fuzz in fuzz test harnesses. None of the fixes represent real issues.
attribute.FuzzHashKVs(OSS-Fuzz564808681โ >60s Timeout)FuzzHashKVscopieskvsintomodifiedKvsand mutatesmodifiedKvs[0]to check for hash collisions viaif h1 == h3 && !reflect.DeepEqual(kvs, modifiedKvs). However, severalmodifiedKvs[0]types and values were left unmodified by theswitchstatement:FLOAT64whenf1isNaN,ยฑInf(NaN + 1.0is stillNaNwith identical bits,ยฑInf + 1.0 == ยฑInf), or a large float (|f1| >= 2^53, wheref1 + 1.0 == f1).BOOLSLICE,INT64SLICE,FLOAT64SLICE,STRINGSLICE, andBYTESLICE(omitted from theswitch).SLICEandMAPwhen empty (len == 0).modifiedKvs[0]was left unmodified (h1 == h3) andkvsalso contained aFloat64Slicewithmath.NaN()(whichFuzzHashKVsunconditionally constructs whenbhas0x7ff8...bytes),reflect.DeepEqual(kvs, modifiedKvs)returnedfalsebecausereflect.DeepEqual(NaN, NaN)is alwaysfalsein Go. This falsely triggeredt.Logf("Potential hash collision detected: original=%v, modified=%v, hash=%d", kvs, modifiedKvs, h1). Under OSS-Fuzz'sgo-118-fuzz-buildadapter,t.Logfunconditionally prints tostdout. After attribute: add String method for KeyValueย #8205 addedKeyValue.String()(which serializesSliceValueandMapValueas JSON viaappendJSONString), formatting bothkvsandmodifiedKvswith a 263 KB invalid-UTF-8 stringsserialized 8 copies ofs(~18 MB of\ufffd-escaped JSON) under-gcflags=all=-d=libfuzzercomparison instrumentation, taking ~150 seconds for a single input.modifiedKvs[0]is mutated across all value types and edge cases (replacing non-finite floats with0.0, usingmath.Nextafterwhenval + 1.0 == val, handling all primitive slice types, and mutating emptySLICE/MAPvalues), and avoid formatting the fullkvsslices int.Logf.sdk/metric/internal/aggregate.FuzzGetBin(OSS-Fuzz458865858, Closes [Fuzzing]FuzzGetBinreports errorย #7576)FuzzGetBinpassed arbitraryfloat64values directly togetBin(v). In production,expoHistogram.measurefilters outยฑInfandNaNbefore recording values, andlowerBound(bin, scale)loses precision in the subnormalfloat64range (v < 0x1p-1022) where IEEE-754 subnormal numbers have fewer than 53 significand bits (e.g.,0x1p-1069has only 5 bits of precision, causinglowerBound(getBin(0x1p-1069), 6)to round up to0x1p-1069and fail thelowerBound < vassertion).v < smallestNonZeroNormalFloat64 || math.IsInf(v, 0) || math.IsNaN(v)inFuzzGetBin.trace.FuzzSpanIDFromHex&trace.FuzzTraceIDFromHex(OSS-Fuzz498709184)validTraceIDRe := regexp.MustCompile(...)andvalidSpanIDRe := regexp.MustCompile(...)were placed insideFuzzTraceIDFromHex(f *testing.F)andFuzzSpanIDFromHex(f *testing.F)outsidef.Fuzz(...). While standardgo test -fuzzruns the outerFuzz*(f)setup once per process, OSS-Fuzz'sgo-118-fuzz-buildadapter (LLVMFuzzerTestOneInput->LibFuzzerFuzzSpanIDFromHex) callsFuzzSpanIDFromHex(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, andSIGURGasync preemption signal pressure in the Goc-archive+libFuzzer/ASANruntime.validTraceIDReandvalidSpanIDReto package-level variables so they are compiled once at package initialization.