Skip to content

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

Merged
jtdavis777 merged 2 commits intogoogle:masterfrom
dataCenter430:fix-annotated-output-for-size-prefixed-binaries
Mar 19, 2026
Merged

Fix --annotated + --size-prefixed generating empty annotated files#8976
jtdavis777 merged 2 commits 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

@dataCenter430
Copy link
Contributor Author

Hi, @jtdavis777 sorry to ping you, I know you're so busy.
Could you please review the PR, when you have a moment?
Best regards

@jtdavis777
Copy link
Collaborator

making sure I understand this right -- the binary file passed into this command would influence how the bfbs file was verified? and that is the gist of the bug? So now we verify the bfbs unconditionally, and only return an empty file if the bfbs is invalid?

@jtdavis777 jtdavis777 added the waiting-for-update This PR is waiting for a change from the author or contributors before it is ready for merge label Mar 19, 2026
@dataCenter430
Copy link
Contributor Author

dataCenter430 commented Mar 19, 2026

Hi, @jtdavis777 thanks for your review.
Yes, exactly right. The is_size_prefixed_ flag was derived from the data binary (prefixed_sample.dat), but was then mistakenly applied to verify the schema (.bfbs).
So passing a size-prefixed data binary would cause the schema verification to fail — the schema had nothing to do with the data binary being size-prefixed.
The fix verifies the .bfbs unconditionally as a plain schema, and only returns empty if the schema itself is genuinely invalid.
Thanks again

@jtdavis777 jtdavis777 merged commit 93f587a into google:master Mar 19, 2026
51 checks passed
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 waiting-for-update This PR is waiting for a change from the author or contributors before it is ready for merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

--size-prefixed generates empty annotated file

2 participants