Skip to content

Commit 206af5c

Browse files
authored
Merge pull request #11 from go-avro/fuzz-fix-specific-union
Fix: don't panic for out-of-range on corrupted union decoding.
2 parents a7edd34 + 18b258d commit 206af5c

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

datum_reader.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -346,13 +346,15 @@ func (reader sDatumReader) mapEnum(field Schema, dec Decoder) (reflect.Value, er
346346
}
347347

348348
func (reader sDatumReader) mapUnion(field Schema, reflectField reflect.Value, dec Decoder) (reflect.Value, error) {
349-
unionType, err := dec.ReadInt()
349+
unionIndex, err := dec.ReadInt()
350350
if err != nil {
351-
return reflect.ValueOf(unionType), err
351+
return reflect.ValueOf(unionIndex), err
352352
}
353-
354-
union := field.(*UnionSchema).Types[unionType]
355-
return reader.readValue(union, reflectField, dec)
353+
types := field.(*UnionSchema).Types
354+
if unionIndex < 0 || int(unionIndex) >= len(types) {
355+
return reflect.Value{}, fmt.Errorf("Invalid union index %d", unionIndex)
356+
}
357+
return reader.readValue(types[unionIndex], reflectField, dec)
356358
}
357359

358360
func (reader sDatumReader) mapFixed(field Schema, dec Decoder) (reflect.Value, error) {

0 commit comments

Comments
 (0)