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 size of type_id in Object.set_crystal_type_id #13338

Merged

Conversation

straight-shoota
Copy link
Member

@straight-shoota straight-shoota commented Apr 18, 2023

The type of crystal_type_id is Int32, not LibC::SizeT. On 64-bit systems this wrong size would write a 64-bit integer into a space that's only suppose to be 32-bit wide.

This bug has limited practical effect. Due to byte ordering the memory representation of 32-bit and small 64-bit values are (usually) identical. The type id is never wider than 32-bits so this works correctly. The only negative side effect would be overriding the first 4 bytes of the object data that follows the type id.
This method is only called from WeakRef.allocate on an empty object where this is irrelevant.

It's sill a bug and needs to be fixed. For the fix I opted to infer the type based on the type of crystal_instance_type_id (which is a compiler primitive). The size does not need to be hard-coded into stdlib.

@straight-shoota straight-shoota added this to the 1.9.0 milestone Apr 18, 2023
@straight-shoota straight-shoota merged commit 24ea737 into crystal-lang:master Apr 20, 2023
45 checks passed
@straight-shoota straight-shoota deleted the fix/set_crystal_type branch April 20, 2023 08:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants