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

fix: Match the complete BcSymbolMap header (NATIVE-281) #523

Merged
merged 2 commits into from
Mar 29, 2022

Conversation

Swatinem
Copy link
Member

Previously, the match was truncated to the input buffer length, which meant that
empty files always passed the check, which they obviously should not.

@Swatinem Swatinem requested a review from a team March 29, 2022 09:08
Previously, the match was truncated to the input buffer length, which meant that
empty files always passed the check, which they obviously should not.
@Swatinem Swatinem merged commit 10ccd26 into master Mar 29, 2022
@Swatinem Swatinem deleted the fix/bcsymbolmap-test branch March 29, 2022 11:09
Copy link
Contributor

@flub flub left a comment

Choose a reason for hiding this comment

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

I can't request changes anymore... but I fear this breaks things

let buf = b"oops";
assert!(!BcSymbolMap::test(&buf[..]));
assert!(BcSymbolMap::test(b"BCSymbolMap Version: 2.0"));
assert!(!BcSymbolMap::test(b"BCSymbolMap Vers"));
Copy link
Contributor

Choose a reason for hiding this comment

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

IIRC it is important that this does pass the test, I suspect if sentry-cli adopts this you won't be able to upload any bcsymbolmaps anymore.

@@ -433,7 +428,7 @@ mod tests {
)
.unwrap();

assert!(BcSymbolMap::test(&data.as_bytes()[..20]));
assert!(BcSymbolMap::test(data.as_bytes()));
Copy link
Contributor

Choose a reason for hiding this comment

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

likely this 20 bytes was therefore also not an accidental number

@Swatinem
Copy link
Member Author

Looking at this in more detail, I see two code paths calling BcSymbolMap::test/open in sentry-cli, both get a ByteView, which is either mmaped via .open() or read from a zip stream via .read() which according to its docs exhausts the whole read stream.

@Swatinem
Copy link
Member Author

Either way, we can also back out "half" of the change, meaning: Allow truncating down to ~20bytes. Archive::peek makes a cut at 16 bytes btw.

@flub
Copy link
Contributor

flub commented Mar 29, 2022

Archive::peek makes a cut at 16 bytes btw.

Is this what I recall then? If sentry-cli looks inside an archive this test only gets called with 16 bytes? That would still mean we want it to consider it a match if there are fewer bytes matching.

IIRC this test method is supposed to be best effort, so if you only provide a slice of say 4 bytes and they match the first 4 bytes of our prefix it should still say "this could be a bcsymbolmap". though obviously doing this at 0 bytes is taking it too far :)

@Swatinem
Copy link
Member Author

Oh what I meant to refer to was this:

if data.len() < 16 {
return FileFormat::Unknown;
}

Symbolic needs at least 16 bytes to actually detect anything. It does not truncate, only checks for that.

Other longer file headers are also checked for precisely:

data.starts_with(MAGIC_BIG)

@flub
Copy link
Contributor

flub commented Mar 30, 2022

hum, did some spelunking in the sentry-cli codebase as well and I can't find a reason for the requirement to be able to do partial matches, though I'm like 100% sure this was a requirement and that this was done explicitly like this before. I think these API's are a bit meh as they are, they require a "large enough" slice but you're left not knowing what "large enough" means is as a caller. So whatever, I guess it's fine, thanks for having a look as well.

@Swatinem
Copy link
Member Author

Hm, maybe we should have a look at the sentry codebase itself, as it pulls in parts of the symbolic python API.

@flub
Copy link
Contributor

flub commented Mar 30, 2022

good point, though it seems the test methods aren't even exposed on the python API and sentry re-implements this: https://github.com/getsentry/sentry/blob/master/src/sentry/models/debugfile.py#L421-L433

@Swatinem
Copy link
Member Author

👍🏻 thanks for looking into this, in which case I think we are good.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants