Skip to content

Conversation

@brianmacy
Copy link

Summary

Fixes #8894

The write_vtable() function's comment claimed to "fill the WIP vtable with zeros" but make_space() only reserves memory without initializing it. When using custom allocators with non-zeroed buffers, unset vtable field entries would contain garbage instead of zero (which indicates "use default value").

Changes:

  • Added explicit zeroing of vtable memory after reserving space, matching the C++ implementation's buf_.fill_big() behavior
  • Added regression test using a garbage-filled allocator (0xAA) that verifies vtable entries for unset fields are properly zeroed

Test plan

  • New unit test test_vtable_zeroed_with_garbage_allocator added
  • Test fails without fix (shows 0xAAAA garbage in vtable)
  • Test passes with fix
  • All existing Rust tests pass

@google-cla
Copy link

google-cla bot commented Jan 3, 2026

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@github-actions github-actions bot added the rust label Jan 3, 2026
@jtdavis777
Copy link
Collaborator

I don't think any of our other tests are written in source -- is there a way to test this from the tests directory? Or do you need intimate access to create the allocator? I am not a rust person :)

@brianmacy
Copy link
Author

I barely know Rust either. This is just the way I've seen it done. I'm sure I can follow the pattern of the others if needed.

…d data

The write_vtable() function's comment claimed to "fill the WIP vtable
with zeros" but make_space() only reserves memory without initializing
it. When using custom allocators with non-zeroed buffers, unset vtable
field entries would contain garbage instead of zero (which indicates
"use default value").

This fix explicitly zeros the vtable memory after reserving space,
matching the C++ implementation's buf_.fill_big() behavior.

Added regression test using a garbage-filled allocator (0xAA) that
verifies vtable entries for unset fields are properly zeroed.

Fixes google#8894
@brianmacy brianmacy force-pushed the fix-rust-vtable-uninitialized-memory branch from 248e3c7 to abbe488 Compare January 4, 2026 17:07
@brianmacy
Copy link
Author

I think that resolves it.

@brianmacy
Copy link
Author

I don't think any of our other tests are written in source -- is there a way to test this from the tests directory? Or do you need intimate access to create the allocator? I am not a rust person :)

Now that tat is fixed, let me know if there is anything else I need to do.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Rust write_vtable leave uninitialized values

2 participants