Skip to content

Commit d67210d

Browse files
committed
fix: guard against slice panic on single-char quoted strings in parseTypeFromString
Fuzz testing found that a bare quote character (e.g. `"`) matched the forward reference check but caused s[1:0] slice panic. Add len >= 2 guard before slicing.
1 parent 76cc3b4 commit d67210d

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

pkg/schema/python/parser.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -686,8 +686,9 @@ func parseTypeFromString(s string) (schema.TypeAnnotation, bool) {
686686
}
687687

688688
// Forward reference: quoted string like "MyType" or 'MyType'
689-
if (strings.HasPrefix(s, "\"") && strings.HasSuffix(s, "\"")) ||
690-
(strings.HasPrefix(s, "'") && strings.HasSuffix(s, "'")) {
689+
if len(s) >= 2 &&
690+
((strings.HasPrefix(s, "\"") && strings.HasSuffix(s, "\"")) ||
691+
(strings.HasPrefix(s, "'") && strings.HasSuffix(s, "'"))) {
691692
inner := s[1 : len(s)-1]
692693
return parseTypeFromString(inner)
693694
}

0 commit comments

Comments
 (0)