Skip to content

Fix --annotated + --size-prefixed generating empty annotated files#8976

Open
dataCenter430 wants to merge 1 commit intogoogle:masterfrom
dataCenter430:fix-annotated-output-for-size-prefixed-binaries
Open

Fix --annotated + --size-prefixed generating empty annotated files#8976
dataCenter430 wants to merge 1 commit intogoogle:masterfrom
dataCenter430:fix-annotated-output-for-size-prefixed-binaries

Conversation

@dataCenter430
Copy link
Contributor

@dataCenter430 dataCenter430 commented Mar 12, 2026

Closes: #8953

Summary

  • Fixes an issue where running flatc --size-prefixed --annotated <schema>.fbs -- <binary> would generate an almost empty annotated file.
  • Ensures that the reflection schema used by BinaryAnnotator is always validated as a normal (non–size-prefixed) schema, independent of whether the input binary is size-prefixed.
  • Keeps is_size_prefixed_ scoped correctly to parsing the data buffer header only.

Description

Previously, BinaryAnnotator::Annotate validated the schema buffer like this:

  • If is_size_prefixed_ was true (because the input binary was size-prefixed), it attempted reflection::VerifySizePrefixedSchemaBuffer.
  • If that failed, or if reflection::VerifySchemaBuffer failed, it returned an empty section map.

In the --annotated flow, the schema (.bfbs) is not size-prefixed, even when the binary data is. This caused schema verification to fail when --size-prefixed was used, leading to an empty annotation result and an almost empty .afb file.

This PR changes BinaryAnnotator::Annotate to always validate the schema using:

if (!reflection::VerifySchemaBuffer(verifier)) {
  return {};
}

@github-actions github-actions bot added c++ codegen Involving generating code from schema labels Mar 12, 2026
@dataCenter430
Copy link
Contributor Author

Hi, @dbaileychess
Please reivew the PR when you have a chance.
Thanks

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

Labels

c++ codegen Involving generating code from schema

Projects

None yet

Development

Successfully merging this pull request may close these issues.

--size-prefixed generates empty annotated file

1 participant