mirror of
https://github.com/anchore/syft.git
synced 2026-05-20 04:05:24 +02:00
fix(lua-rockspec): handle empty and whitespace-only rockspec files gracefully (#4827)
Empty or whitespace-only .rockspec files cause parseRockspecBlock to panic with "index out of range" because the existing end-of-data guard requires len(out) > 0 before returning the "unexpected end of block" error, letting the bare data[*i] access on the next line crash. Split the guard so that: - partial content at end of data still returns the existing error - empty data (or whitespace-only) returns an empty block cleanly Closes #4824. Signed-off-by: Akihiko Komada <aki1770@gmail.com>
This commit is contained in:
parent
014a4c9c59
commit
3562dab445
@ -63,8 +63,11 @@ func parseRockspecBlock(data []byte, i *int, locals map[string]string) ([]rocksp
|
|||||||
|
|
||||||
parsing.SkipWhitespace(data, i)
|
parsing.SkipWhitespace(data, i)
|
||||||
|
|
||||||
if *i >= len(data) && len(out) > 0 {
|
if *i >= len(data) {
|
||||||
return nil, fmt.Errorf("unexpected end of block at %d", *i)
|
if len(out) > 0 {
|
||||||
|
return nil, fmt.Errorf("unexpected end of block at %d", *i)
|
||||||
|
}
|
||||||
|
return out, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
c := data[*i]
|
c := data[*i]
|
||||||
|
|||||||
@ -14,6 +14,17 @@ func Test_parseRockspecData(t *testing.T) {
|
|||||||
content string
|
content string
|
||||||
wantErr require.ErrorAssertionFunc
|
wantErr require.ErrorAssertionFunc
|
||||||
}{
|
}{
|
||||||
|
{
|
||||||
|
name: "empty file",
|
||||||
|
content: ``,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "whitespace only",
|
||||||
|
content: `
|
||||||
|
|
||||||
|
|
||||||
|
`,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: "basic valid content",
|
name: "basic valid content",
|
||||||
content: `
|
content: `
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user