From 417a16ed941c86e8091fcbb863a7a9411c4ba5d9 Mon Sep 17 00:00:00 2001 From: Alexander Bayandin Date: Wed, 17 Feb 2021 21:57:18 +0000 Subject: [PATCH] Fix edge case panic in ParseID (#1249) --- stripe.go | 5 +++++ stripe_test.go | 7 +++++++ 2 files changed, 12 insertions(+) diff --git a/stripe.go b/stripe.go index 9be3fc607d..67b5e6e759 100644 --- a/stripe.go +++ b/stripe.go @@ -977,6 +977,11 @@ func ParseID(data []byte) (string, bool) { return "", false } + // Edge case that should never happen; found via fuzzing + if s == "\"" { + return "", false + } + return s[1 : len(s)-1], true } diff --git a/stripe_test.go b/stripe_test.go index 467ed81504..0ddea312fb 100644 --- a/stripe_test.go +++ b/stripe_test.go @@ -777,6 +777,13 @@ func TestParseID(t *testing.T) { assert.Equal(t, "", id) assert.False(t, ok) } + + // Edge case that should never happen; found via fuzzing + { + id, ok := ParseID([]byte(`"`)) + assert.Equal(t, "", id) + assert.False(t, ok) + } } // TestMultipleAPICalls will fail the test run if a race condition is thrown while running multiple NewRequest calls.