Skip to content

Commit 5754b3e

Browse files
authored
Merge pull request #197 from kcasctiv/fix-get-infinite-loop
Fix infinite loop in Get
2 parents 57853d8 + b10e032 commit 5754b3e

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

parser.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,9 @@ func searchKeys(data []byte, keys ...string) int {
294294
// can move to the end of this block
295295
if !lastMatched {
296296
end := blockEnd(data[i:], '{', '}')
297+
if end == -1 {
298+
return -1
299+
}
297300
i += end - 1
298301
} else {
299302
level++

parser_test.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -861,9 +861,15 @@ var getTests = []GetTest{
861861
},
862862
{
863863
// Issue #178: Crash in searchKeys
864-
desc: `invalid json`,
865-
json: `{{{"":`,
866-
path: []string{"a", "b"},
864+
desc: `invalid json`,
865+
json: `{{{"":`,
866+
path: []string{"a", "b"},
867+
isFound: false,
868+
},
869+
{
870+
desc: `opening brace instead of closing and without key`,
871+
json: `{"a":1{`,
872+
path: []string{"b"},
867873
isFound: false,
868874
},
869875
}

0 commit comments

Comments
 (0)