fix(lua-rockspec): handle empty and whitespace-only rockspec files gracefully#4827
Merged
Merged
Conversation
…acefully 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 anchore#4824. Co-Authored-By: Claude and aki1770-del <aki1770@gmail.com> Signed-off-by: Akihiko Komada <aki1770@gmail.com>
kzantow
approved these changes
Apr 24, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #4824.
Problem
Scanning a container image that contains an empty
.rockspecfile causes syft to panic withruntime error: index out of range [0] with length 0.The bug is in
parseRockspecBlockatsyft/pkg/cataloger/lua/rockspec_parser.go:66:The guard condition requires
len(out) > 0— for an empty file,outis empty anddatais empty, so the guard falls through toc := data[0], which panics.Fix
Split the guard so empty input returns gracefully:
Preserves the existing "unexpected end of block" error for partial content; returns an empty block cleanly for empty or whitespace-only input.
Tests
Added two cases to
rockspec_parser_test.go:empty fileandwhitespace only— both expect no error and empty result.