Skip to content

Commit ba404a0

Browse files
committed
Correct fix for long MSI interned strings (#25104)
h/t binref/refinery#72, for #24720. No changes file as this is an unreleased bug. Also added output for version in the custom package parser tool. # Checklist for submitter If some of the following don't apply, delete the relevant line. <!-- Note that API documentation changes are now addressed by the product design team. --> - [x] Changes file added for user-visible changes in `changes/`, `orbit/changes/` or `ee/fleetd-chrome/changes`. See [Changes files](https://github.com/fleetdm/fleet/blob/main/docs/Contributing/Committing-Changes.md#changes-files) for more information. - [x] Manual QA for all new/changed functionality
1 parent 661c067 commit ba404a0

File tree

2 files changed

+9
-13
lines changed

2 files changed

+9
-13
lines changed

pkg/file/msi.go

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -242,24 +242,20 @@ func decodeStrings(dataReader, poolReader io.Reader) ([]string, error) {
242242
}
243243
return nil, fmt.Errorf("failed to read pool entry: %w", err)
244244
}
245-
stringEntrySize := int(stringEntry.Size)
245+
stringEntrySize := uint32(stringEntry.Size)
246246

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

261257
buf.Reset()
262-
buf.Grow(stringEntrySize)
258+
buf.Grow(int(stringEntrySize))
263259
_, err = io.CopyN(&buf, dataReader, int64(stringEntrySize))
264260
if err != nil {
265261
return nil, fmt.Errorf("failed to read string data: %w", err)

tools/custom-package-parser/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ func main() {
3131
}
3232

3333
fmt.Printf(
34-
"- Name: '%s'\n- Bundle Identifier: '%s'\n- Package IDs: '%s'\n",
35-
metadata.Name, metadata.BundleIdentifier, strings.Join(metadata.PackageIDs, ","),
34+
"- Name: '%s'\n- Bundle Identifier: '%s'\n- Package IDs: '%s'\n- Version: %s\n\n",
35+
metadata.Name, metadata.BundleIdentifier, strings.Join(metadata.PackageIDs, ","), metadata.Version,
3636
)
3737
}
3838

0 commit comments

Comments
 (0)