Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cherry-Pick: Correct fix for long MSI interned strings #25107

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 7 additions & 11 deletions pkg/file/msi.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,24 +242,20 @@ func decodeStrings(dataReader, poolReader io.Reader) ([]string, error) {
}
return nil, fmt.Errorf("failed to read pool entry: %w", err)
}
stringEntrySize := int(stringEntry.Size)
stringEntrySize := uint32(stringEntry.Size)

// For string pool entries too long for the size to fit in a single uint16, entry size is 8 bytes instead of 4,
// with the first two bytes as zeroes, the next two are the two most-significant bytes of the size, shifted
// 17 (?!?) bits to the left, the following two are the less-significant bits of the size, and the last two are
// the reference count. Verified with the OpenVPN Connect v3 installer, which has a large string blob for
// licenses where a 17-bit shift captures the length properly.
// For string pool entries too long for the size to fit in a single uint16, the format sets the size as zero,
// maintains the reference count location in the structure, then uses the following four bytes (little-endian)
// to store the string size. See https://github.com/binref/refinery/issues/72.
if stringEntry.Size == 0 && stringEntry.RefCount != 0 {
stringEntrySize = int(stringEntry.RefCount) << 17
err := binary.Read(poolReader, binary.LittleEndian, &stringEntry)
err := binary.Read(poolReader, binary.LittleEndian, &stringEntrySize)
if err != nil {
return nil, fmt.Errorf("failed to read large string pool entry: %w", err)
return nil, fmt.Errorf("failed to read size of large string in string pool: %w", err)
}
stringEntrySize += int(stringEntry.Size)
}

buf.Reset()
buf.Grow(stringEntrySize)
buf.Grow(int(stringEntrySize))
_, err = io.CopyN(&buf, dataReader, int64(stringEntrySize))
if err != nil {
return nil, fmt.Errorf("failed to read string data: %w", err)
Expand Down
4 changes: 2 additions & 2 deletions tools/custom-package-parser/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ func main() {
}

fmt.Printf(
"- Name: '%s'\n- Bundle Identifier: '%s'\n- Package IDs: '%s'\n",
metadata.Name, metadata.BundleIdentifier, strings.Join(metadata.PackageIDs, ","),
"- Name: '%s'\n- Bundle Identifier: '%s'\n- Package IDs: '%s'\n- Version: %s\n\n",
metadata.Name, metadata.BundleIdentifier, strings.Join(metadata.PackageIDs, ","), metadata.Version,
)
}

Expand Down
Loading