Fix decode error for dictionary-encoded structs#354
Merged
tigrannajaryan merged 1 commit intomainfrom Feb 15, 2026
Merged
Conversation
The problem occurs when decoding dictionary-encoded structs and the refNum is 0, which corresponds to nil struct. Nil is not allowed for structs unless they are optional. Decoding error is found by FuzzSampleReader and corresponding seeds are included in this PR.
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes a decode failure when dictionary-encoded struct references use refNum == 0 (nil) in contexts where nil structs are invalid, and adds fuzz-regression seeds capturing the issue.
Changes:
- Add explicit nil checks after decoding dict-encoded struct pointers (reject nil for non-optional/invalid cases).
- Add a generic
pkg.ErrDecodeErrorsentinel used for “invalid decode state” returns. - Refactor many generated decoders to use inline
if err := ...; err != nilstyle and adjust oneof decoders to surface buffer errors immediately after reading the variant type.
Reviewed changes
Copilot reviewed 51 out of 51 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| stefc/templates/go/struct.go.tmpl | Add nil rejection for non-optional dict-encoded pointer fields after decode; simplify error handling. |
| stefc/templates/go/oneof.go.tmpl | Check buffer error after reading oneof type; reject nil for dict-encoded pointer variants; return nil when no further buffer interaction is needed. |
| stefc/templates/go/array.go.tmpl | Reject nil elements for dict-encoded struct arrays; simplify error handling in loops. |
| go/pkg/errors.go | Introduce ErrDecodeError decode-error sentinel. |
| go/otel/otelstef/uint64array.go | Inline decode error handling style cleanup. |
| go/otel/otelstef/summaryvalue.go | Inline decode error handling style cleanup. |
| go/otel/otelstef/spanstatus.go | Inline decode error handling style cleanup. |
| go/otel/otelstef/spans.go | Inline decode error handling; reject nil for non-optional dict-decoded struct pointers. |
| go/otel/otelstef/span.go | Inline decode error handling style cleanup. |
| go/otel/otelstef/scope.go | Inline decode error handling style cleanup. |
| go/otel/otelstef/resource.go | Inline decode error handling style cleanup. |
| go/otel/otelstef/quantilevaluearray.go | Inline decode error handling style cleanup. |
| go/otel/otelstef/quantilevalue.go | Inline decode error handling style cleanup. |
| go/otel/otelstef/pointvalue.go | Oneof: check buffer error after reading type; return nil at end. |
| go/otel/otelstef/point.go | Inline decode error handling style cleanup. |
| go/otel/otelstef/metrics.go | Inline decode error handling; reject nil for non-optional dict-decoded struct pointers. |
| go/otel/otelstef/metric.go | Inline decode error handling style cleanup. |
| go/otel/otelstef/linkarray.go | Inline decode error handling style cleanup. |
| go/otel/otelstef/link.go | Inline decode error handling style cleanup. |
| go/otel/otelstef/histogramvalue.go | Inline decode error handling style cleanup. |
| go/otel/otelstef/float64array.go | Inline decode error handling style cleanup. |
| go/otel/otelstef/exphistogramvalue.go | Inline decode error handling style cleanup. |
| go/otel/otelstef/exphistogrambuckets.go | Inline decode error handling style cleanup. |
| go/otel/otelstef/exemplarvalue.go | Oneof: check buffer error after reading type; return nil at end. |
| go/otel/otelstef/exemplararray.go | Inline decode error handling style cleanup. |
| go/otel/otelstef/exemplar.go | Inline decode error handling style cleanup. |
| go/otel/otelstef/eventarray.go | Inline decode error handling style cleanup. |
| go/otel/otelstef/event.go | Inline decode error handling style cleanup. |
| go/otel/otelstef/envelope.go | Inline decode error handling style cleanup. |
| go/otel/otelstef/anyvaluearray.go | Inline decode error handling style cleanup. |
| go/otel/otelstef/anyvalue.go | Oneof: check buffer error after reading type; return nil at end. |
| examples/profile/internal/profile/testdata/fuzz/FuzzSampleReader/d369e9adf349dff1 | Add fuzz seed reproducing the decode issue. |
| examples/profile/internal/profile/testdata/fuzz/FuzzSampleReader/814b20d96326fa74 | Add fuzz seed reproducing the decode issue. |
| examples/profile/internal/profile/stringarray.go | Inline decode error handling style cleanup. |
| examples/profile/internal/profile/samplevaluetype.go | Inline decode error handling style cleanup. |
| examples/profile/internal/profile/samplevaluearray.go | Inline decode error handling style cleanup. |
| examples/profile/internal/profile/samplevalue.go | Inline decode error handling; reject nil for non-optional dict-decoded struct pointers. |
| examples/profile/internal/profile/sample.go | Inline decode error handling style cleanup. |
| examples/profile/internal/profile/profilemetadata.go | Inline decode error handling; reject nil for non-optional dict-decoded struct pointers. |
| examples/profile/internal/profile/numvalue.go | Inline decode error handling style cleanup. |
| examples/profile/internal/profile/mapping.go | Inline decode error handling style cleanup. |
| examples/profile/internal/profile/locationarray.go | Reject nil elements for dict-encoded struct arrays; inline decode error handling. |
| examples/profile/internal/profile/location.go | Inline decode error handling; reject nil for non-optional dict-decoded struct pointers. |
| examples/profile/internal/profile/linearray.go | Inline decode error handling style cleanup. |
| examples/profile/internal/profile/line.go | Inline decode error handling; reject nil for non-optional dict-decoded struct pointers. |
| examples/profile/internal/profile/labelvalue.go | Oneof: check buffer error after reading type; return nil at end. |
| examples/profile/internal/profile/function.go | Inline decode error handling style cleanup. |
| examples/jsonl/internal/jsonstef/record.go | Inline decode error handling style cleanup. |
| examples/jsonl/internal/jsonstef/jsonvaluearray.go | Inline decode error handling style cleanup. |
| examples/jsonl/internal/jsonstef/jsonvalue.go | Oneof: check buffer error after reading type; return nil at end. |
| examples/ints/internal/ints/record.go | Inline decode error handling style cleanup. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Benchmark ResultBenchmark diff with base branchBenchmark result |
Collaborator
Author
|
Merging this one to continue fuzzing. |
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.
The problem occurs when decoding dictionary-encoded structs and the refNum is 0, which corresponds to nil struct. Nil is not allowed for structs unless they are optional.
Decoding error is found by FuzzSampleReader and corresponding seeds are included in this PR.