chore: revert custom index in favor of key_Split

Signed-off-by: Keith Zantow <keith.zantow@anchore.com>
This commit is contained in:
Keith Zantow
2026-09-20 11:22:10 -04:00
parent 99615b7dfa
commit 53cd4254e4
81 changed files with 7461 additions and 6624 deletions
+1 -2
View File
@@ -8,8 +8,7 @@ import (
const perFileReadLimit = 2 * GB
// SafeCopy limits the copy from the reader. This is useful when extracting files from archives to
// protect against decompression bomb attacks.
// SafeCopy bounds the copy to guard against decompression bombs when extracting from archives.
func SafeCopy(writer io.Writer, reader io.Reader) error {
numBytes, err := io.Copy(writer, io.LimitReader(reader, perFileReadLimit))
if numBytes >= perFileReadLimit {
+1 -13
View File
@@ -165,22 +165,10 @@ func UnzipToDir(ctx context.Context, archivePath, targetDir string) error {
}
// SafeJoin ensures that any destinations do not resolve to a path above the prefix path.
//
// The comparison is on a path boundary rather than on the string prefix. A sibling directory that
// happens to share the prefix as a string is not inside it: under "/tmp/x/contents" the destination
// "../contents-evil/y" cleans to "/tmp/x/contents-evil/y", which starts with the prefix and is
// outside it.
func SafeJoin(prefix string, dest ...string) (string, error) {
joinResult := filepath.Join(append([]string{prefix}, dest...)...)
cleanPrefix := filepath.Clean(prefix)
cleanJoinResult := filepath.Clean(joinResult)
boundary := cleanPrefix
if !strings.HasSuffix(boundary, string(filepath.Separator)) {
boundary += string(filepath.Separator)
}
if cleanJoinResult != cleanPrefix && !strings.HasPrefix(cleanJoinResult, boundary) {
if !strings.HasPrefix(cleanJoinResult, filepath.Clean(prefix)) {
return "", &errZipSlipDetected{
Prefix: prefix,
JoinArgs: dest,
-39
View File
@@ -305,45 +305,6 @@ func TestSafeJoin(t *testing.T) {
expected: "",
errAssertion: assertErrorAs(&errZipSlipDetected{}),
},
// a legitimate nested path, several components deep
{
prefix: "/a/place",
args: []string{
"lib",
"sub",
"file.txt",
},
expected: "/a/place/lib/sub/file.txt",
errAssertion: assert.NoError,
},
// the prefix itself is inside the prefix
{
prefix: "/a/place",
args: []string{
".",
},
expected: "/a/place",
errAssertion: assert.NoError,
},
// siblings that share the prefix as a STRING are not inside it. A string-prefix comparison
// accepted these, so an archive entry could write into a directory next to the one it was
// being extracted into.
{
prefix: "/a/place",
args: []string{
"../place-evil/x",
},
expected: "",
errAssertion: assertErrorAs(&errZipSlipDetected{}),
},
{
prefix: "/tmp/syft-archive-abc/contents",
args: []string{
"../contents-evil/x",
},
expected: "",
errAssertion: assertErrorAs(&errZipSlipDetected{}),
},
}
for _, test := range tests {