Uh oh!
There was an error while loading. Please reload this page.
[browser] Webcil alignment - #124905
Conversation
There was a problem hiding this comment.
Pull request overview
This PR updates the Webcil toolchain (converter/reader + build integration) to standardize naming, introduce 16-byte section alignment in Webcil payloads, and improve correctness around debug directory fixups and big-endian parsing.
Changes:
- Align Webcil section raw data to 16-byte boundaries (with zero padding) and update debug-directory fixups to translate file offsets per-section rather than via a single constant adjustment.
- Fix a big-endian header parsing bug in
WebcilReaderand add stricter RVA/bounds validation when translating RVAs to file offsets. - Rename Webcil-related APIs/targets/properties (e.g.,
WebCil*→Webcil*,ConvertDllsToWebCil→ConvertDllsToWebcil) and update docs accordingly.
Reviewed changes
Copilot reviewed 14 out of 14 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| src/tasks/Microsoft.NET.WebAssembly.Webcil/WebcilWasmWrapper.cs | Improves internal alignment assertion message for wasm-wrapped payload emission. |
| src/tasks/Microsoft.NET.WebAssembly.Webcil/WebcilReader.cs | Fixes big-endian header parsing and adds bounds checking during RVA translation. |
| src/tasks/Microsoft.NET.WebAssembly.Webcil/WebcilHeader.cs | Renames header fields to PascalCase while preserving layout. |
| src/tasks/Microsoft.NET.WebAssembly.Webcil/WebcilConverter.cs | Adds 16-byte section alignment + padding, reworks debug directory pointer translation, and validates debug dir overwrite size. |
| src/tasks/Microsoft.NET.Sdk.WebAssembly.Pack.Tasks/ConvertDllsToWebCil.cs | Renames MSBuild task/class and output item list for consistent “Webcil” casing. |
| src/tasks/Microsoft.NET.Sdk.WebAssembly.Pack.Tasks/ComputeWasmPublishAssets.cs | Renames IsWebCilEnabled → IsWebcilEnabled and updates related logic. |
| src/mono/wasm/features.md | Updates documentation casing to “Webcil”. |
| src/mono/wasm/Wasm.Build.Tests/Common/BuildEnvironment.cs | Updates env var casing to match WasmEnableWebcil. |
| src/mono/nuget/.../Microsoft.NET.Sdk.WebAssembly.Browser.targets | Updates UsingTask/task invocation/property names to the new “Webcil” casing. |
| src/mono/mono/metadata/webcil-loader.c | Renames internal struct typedef to “Webcil” casing. |
| src/mono/cmake/options.cmake | Updates option description casing. |
| src/mono/cmake/config.h.in | Updates config comment casing. |
| src/mono/browser/debugger/BrowserDebugProxy/DebugStore.cs | Updates comment casing and minor whitespace tweak. |
| docs/design/mono/webcil.md | Updates spec text and documents 16-byte section alignment and rationale. |
Comments suppressed due to low confidence (3)
src/tasks/Microsoft.NET.WebAssembly.Webcil/WebcilConverter.cs:260
CopySectionscomputes padding using(int)outStream.Positionand silently skips padding when the current position is already past the expectedPointerToRawData(negativepaddingNeeded). This can hide layout bugs and can also overflow/truncate for outputs >2GB. Consider doing the math inlong, and throw ifoutStream.Positionis greater than the expected section start (or if the padding would be unexpectedly large), so corrupted Webcil output is detected early.
// Write zero padding to reach the aligned section position
int paddingNeeded = wcSections[i].PointerToRawData - (int)outStream.Position;
if (paddingNeeded > 0)
{
outStream.Write(new byte[paddingNeeded], 0, paddingNeeded);
}
var buffer = new byte[peSections[i].SizeOfRawData];
src/tasks/Microsoft.NET.WebAssembly.Webcil/WebcilConverter.cs:342
TranslateFileOffsetindexeswcSections[i]based on the PE section loop without verifying thatwcSectionshas the same length/order aspeSections. If they ever diverge (corrupt input, future format change), this will throwIndexOutOfRangeExceptionor produce incorrect offsets. Add an upfront length check and a clearer exception (or translate by matching on VirtualAddress/PointerToRawData rather than relying on identical indexing).
private static int TranslateFileOffset(ImmutableArray<SectionHeader> peSections, ImmutableArray<WebcilSectionHeader> wcSections, int peFileOffset)
{
for (int i = 0; i < peSections.Length; i++)
{
var peSection = peSections[i];
if (peFileOffset >= peSection.PointerToRawData && peFileOffset < peSection.PointerToRawData + peSection.SizeOfRawData)
{
int offsetInSection = peFileOffset - peSection.PointerToRawData;
return wcSections[i].PointerToRawData + offsetInSection;
}
src/tasks/Microsoft.NET.WebAssembly.Webcil/WebcilWasmWrapper.cs:189
- This uses
throw new Exception(...)for a deterministic internal consistency check. Elsewhere in this file similar failures useInvalidOperationException; using the baseExceptionmakes the error harder to catch/diagnose consistently. Consider throwingInvalidOperationException(orInvalidDataException) here as well.
if (writer.BaseStream.Position % WebcilPayloadInternalAlignment != 0) {
throw new Exception ($"Expected offset {payloadOffset}, actual position {writer.BaseStream.Position}");
}
pavelsavara
commented
Feb 27, 2026
/ba-g unrelated apple infra |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
PR dotnet#124905 renamed IsWebCilEnabled to IsWebcilEnabled on main. The merge auto-resolved the parameter name but the error message string interpolation still referenced the old casing. Also improved the error message to include asset details and used 'is null' pattern. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Webcil: naming cleanup, section alignment, and bug fixes
Summary
This PR improves the Webcil converter/reader with naming convention fixes, 16-byte section alignment, robust debug directory fixup, and a big-endian correctness bug fix.
Changes
Section alignment
Debug directory fixup improvements
dataPointerAdjustmentapproach with a per-sectionTranslateFileOffsetmethod that correctly maps PE file offsets to webcil file offsets even when sections have different relative positions (due to alignment).GetSectionFromFileOffsetmethods.FixupDebugDirectoryEntriesstatic since it no longer uses instance state.Bug fixes
WebcilReader.ReadHeaderwherepe_debug_sizewas incorrectly assigned tope_debug_rvainstead ofpe_debug_sizeon big-endian platforms.TranslateRVAandGetPositionOfRelativeVirtualAddressto detect RVAs that map beyond a section's raw data.Naming cleanup
WebcilHeaderfields from C-style snake_case (id,version_major,pe_cli_header_rva, etc.) to .NET PascalCase (Id,VersionMajor,PeCliHeaderRva, etc.).WebciHeader.cs→WebcilHeader.cs(was missing the 'l').ConvertDllsToWebCil→ConvertDllsToWebcil,WebCilCandidates→WebcilCandidates,IsWebCilEnabled→IsWebcilEnabled.