mirror of
https://github.com/anchore/syft.git
synced 2026-11-04 08:26:38 +01:00
fix: escape % in ArchivePath segments
`:` was escaped as `%3A`, but `%` itself wasn't, so an entry named `a:b.jar` and one named `a%3Ab.jar` got the same `ArchivePath`. Their contents then collide in `FileMetadata` / `FileDigests` (last writer wins) and share artifact IDs. `%` is now escaped as `%25` before `:`, which makes the encoding injective. The encoding is documented on `Coordinates.ArchivePath` and in the schema. Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>
This commit is contained in:
@@ -85,14 +85,14 @@ func TestVirtualPath(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestVirtualPath_theEscapeCharacterIsNotItselfEscaped(t *testing.T) {
|
||||
// an accepted limit: an entry path holding the literal text %3A is indistinguishable from one holding
|
||||
// a colon. Escaping % too would move many more real identities than it protects.
|
||||
func TestVirtualPath_theEscapeCharacterIsItselfEscaped(t *testing.T) {
|
||||
// an entry path holding the literal text %3A must not collide with one holding a colon, or their
|
||||
// contents share an ArchivePath and overwrite each other's file metadata
|
||||
fromColon := VirtualPath(locationIn("outer.zip", "a:b.jar"))
|
||||
fromLiteral := VirtualPath(locationIn("outer.zip", "a%3Ab.jar"))
|
||||
|
||||
assert.Equal(t, "outer.zip:a%3Ab.jar", fromColon)
|
||||
assert.Equal(t, fromColon, fromLiteral)
|
||||
assert.Equal(t, "outer.zip:a%253Ab.jar", fromLiteral)
|
||||
}
|
||||
|
||||
func TestVirtualPath_escapingComposesAcrossNestingLevels(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user