Skip to content

[BitstreamReader] Fix 32-bit overflow #117363

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

Merged
merged 1 commit into from
Nov 27, 2024
Merged

[BitstreamReader] Fix 32-bit overflow #117363

merged 1 commit into from
Nov 27, 2024

Conversation

pranavk
Copy link
Contributor

@pranavk pranavk commented Nov 22, 2024

This got exposed when processing large LTO-generated files leading to crashes.

Copy link
Collaborator

@rnk rnk left a comment

Choose a reason for hiding this comment

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

Nice find =D

@@ -334,7 +334,8 @@ Expected<unsigned> BitstreamCursor::readRecord(unsigned AbbrevID,

Copy link
Collaborator

Choose a reason for hiding this comment

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

To me this raises a question of whether we want to support writing 4GB+ blobs in bitcode files. We could use ReadVBR64(6) above and EmitVBR64(6) on the writer side, and I think that would be backwards compatible, it just widens the maximum encodable value.

Copy link
Contributor

@mingmingl-llvm mingmingl-llvm Nov 25, 2024

Choose a reason for hiding this comment

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

The change to {Read,Emit}VBR64(6) looks backward compatible to me as well, and https://llvm.org/docs/BitCodeFormat.html#define-abbrev-encoding needs an update around Blob (code 5): This field is emitted as a vbr6, followed by padding to a 32-bit boundary (for alignment) and an array of 8-bit objects It's not clear to me (from the doc and code comment around) how 32-bit alignment is related with value width (32 vs 64) and whether alignment needs an update for 4GB+ blobs.

If we decide not to support 4GB blob soon, I think emitting a release-build visible warning (e.g., by LLVMContext's diagnostic handler) when blob size is larger than 4GB around

EmitVBR(static_cast<uint32_t>(Bytes.size()), 6);
is generally a good change.

@rnk
Copy link
Collaborator

rnk commented Nov 27, 2024

I will merge this as is and file an issue covering the VBR64 change.

@rnk rnk merged commit 8df6321 into llvm:main Nov 27, 2024
9 checks passed
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