Skip to content

Read compiled template streams exactly - #157

Merged
adoconnection merged 1 commit into
adoconnection:masterfrom
dajiaohuang:fix/partial-stream-template-read-c1-563
Oct 22, 2026
Merged

adoconnection merged 1 commit into
adoconnection:masterfrom
dajiaohuang:fix/partial-stream-template-read-c1-563

Conversation

@dajiaohuang

Copy link
Copy Markdown
Contributor

Stream.ReadAsync may return fewer bytes than requested before reaching EOF. The compiled-template reader currently performs one read for each 8-byte length and payload, silently accepting incomplete data and corrupting the loaded template on valid short-read streams.

Read each requested buffer fully, and throw EndOfStreamException if the stream ends prematurely. The regression test round-trips a trusted synthetic Razor template through an in-memory stream that returns at most one byte per async read, then verifies the rendered output.

Validation:

  • Regression failed on the base with "Unable to load template: wrong version" and passed after the fix.
  • Full test suite: dotnet test RazorEngineCore.Tests/RazorEngineCore.Tests.csproj --framework net10.0 — 59 passed.
  • dotnet build RazorEngineCore/RazorEngineCore.csproj --framework netstandard2.0 — passed.
  • git diff --check — passed.

@adoconnection
adoconnection merged commit 831af45 into adoconnection:master Oct 22, 2026
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.

2 participants