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

Handle long interned strings in MSI parsing #25079

Merged
merged 2 commits into from
Jan 2, 2025
Merged

Conversation

iansltx
Copy link
Member

@iansltx iansltx commented Jan 1, 2025

For #24720. Used https://github.com/ChaelChu/msi-props-reader/blob/master/src/msiPropsReader.ts as inspiration. Not sure why the shift is 17 bits rather than 16 here but confirmed that 17 works and 16 doesn't.

Tested against both existing GDrive MSIs for regression testing, plus the one mentioned in the ticket.

Checklist for submitter

If some of the following don't apply, delete the relevant line.

  • Changes file added for user-visible changes in changes/, orbit/changes/ or ee/fleetd-chrome/changes.
    See Changes files for more information.
  • Manual QA for all new/changed functionality

For #24720. Used https://github.com/ChaelChu/msi-props-reader/blob/master/src/msiPropsReader.ts as inspiration. Not sure why the shift is 17 bits rather than 16 here but confirmed that 17 works and 16 doesn't.
Copy link

codecov bot commented Jan 1, 2025

Codecov Report

Attention: Patch coverage is 56.25000% with 7 lines in your changes missing coverage. Please review.

Project coverage is 63.83%. Comparing base (5a30b47) to head (ba28c0c).

Files with missing lines Patch % Lines
pkg/file/msi.go 56.25% 6 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #25079      +/-   ##
==========================================
+ Coverage   63.82%   63.83%   +0.01%     
==========================================
  Files        1614     1614              
  Lines      153582   153596      +14     
  Branches     4040     4040              
==========================================
+ Hits        98026    98051      +25     
+ Misses      47752    47743       -9     
+ Partials     7804     7802       -2     
Flag Coverage Δ
backend 64.70% <56.25%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

pkg/file/msi.go Outdated
@@ -242,9 +242,25 @@ func decodeStrings(dataReader, poolReader io.Reader) ([]string, error) {
}
return nil, fmt.Errorf("failed to read pool entry: %w", err)
}
stringEntrySize := int(stringEntry.Size)

// For string pool entries too long for the size to fit in a single 4-byte entry, we get an 8-byte entry instead,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// For string pool entries too long for the size to fit in a single 4-byte entry, we get an 8-byte entry instead,
// For string pool entries too long for the size to fit in a single 2-byte entry, we get an 4-byte entry instead,

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I actually need to reword this, because the entry is 4 bytes but the size is two bytes of that. Will handle in a sec.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Revised. Let me know if that's sufficiently clear.


// For string pool entries too long for the size to fit in a single 4-byte entry, we get an 8-byte entry instead,
// 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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How did you find this out?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Started with the openvpn-connect v3 MSI, read through the entire string data table (the format is just a bunch of concat'd strings so it's somewhat human-readable if you know what you're looking at), and noticed that the string that was breaking things was a big license blob. Then I just looked for what appeared to be the end of that license blob (fortunately the end was pretty obvious as the next interned string was for a field name or something similar), figured out the approximate length of the license blob from there, then made the assumption that the actual length was "bit shift of first entry refcount value plus second entry size value" based on the JS lib mentioned in the commit note. The length I was seeing was ~65k off of a 16-bit shift so I tried 17 and everything lined up.

Since refinary has the same issue, my guess is we'll get confirmation one way or the other from them trying more MSIs later.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, just curious how you represent a length of e.g. 65536 + 1

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was wondering that too.

Guessing that case will break this again, at which point we'll have enough data to explain this better. Or the refinery issue will explain what's going on here and I'll get a fix in for whatever they find.

Copy link
Member

@lucasmrod lucasmrod left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! A bit confused by the 16 vs 17 bits, but left that as a question.

@iansltx iansltx merged commit 5beeb24 into main Jan 2, 2025
18 of 21 checks passed
@iansltx iansltx deleted the 24720-msi-upload-fix branch January 2, 2025 16:41
iansltx added a commit that referenced this pull request Jan 2, 2025
For #24720. Used
https://github.com/ChaelChu/msi-props-reader/blob/master/src/msiPropsReader.ts
as inspiration. Not sure why the shift is 17 bits rather than 16 here
but confirmed that 17 works and 16 doesn't.

Tested against both existing GDrive MSIs for regression testing, plus
the one mentioned in the ticket.

# 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
iansltx added a commit that referenced this pull request Jan 2, 2025
iansltx added a commit that referenced this pull request Jan 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants