Repository navigation
Fix Windows/MSVC handling of large files - #2748
Conversation
|
For the 64-bit file ops can we do something simpler like? For the stack size do you know why we would need such a high value? IIUC the 8mb limit on linux seems to be enough there. |
|
For the file APIs, I agree the goal is simply to use the 64-bit MSVC CRT variants. I avoided globally redefining For the stack size, one clarification: The reason this is included here is that, after the 64-bit file I/O fix, the large WAT test no longer failed with on Windows. MSVC-linked executables typically default to a 1MB stack reserve, while Linux/macOS environments commonly have larger or configurable stack limits, for example an 8MB soft stack limit on many Linux systems. That likely explains why the same workload can pass on Linux/macOS but fail on Windows. So the larger /STACK value is intended to raise the Windows stack reserve ceiling for very large WAT parsing workloads. It does not mean the process commits that amount of memory at startup. |
177c0d9 to
e5e08dc
Compare
|
CI only reported a clang-format issue. No behavior change. Applied the suggested formatting diff. |
I'd much rather do it by via redefining these macros, keeping the the code otherwise the same on all platforms. There really aren't very many file I/O codepaths in wabt, and I imagine we want to be able to handle large files in all of them. |
Use MSVC macro redirection for stat, fseek, and ftell so the ReadFile path stays shared across platforms. Move the MSVC stack reserve setting into the common wabt_executable helper and reduce it to 8MB.
e5e08dc to
180b6bc
Compare
|
Updated.
Windows x64 verification:
No "value too large", no "unable to read file", and no STATUS_STACK_OVERFLOW with the 8MB stack reserve. |
|
Why do we need to read and write the files in chunks on windows? But not on other platforms? Could you update the PR description to include that maybe? |
|
Are you seeing these error on 64-bit windows too? Or is this mostly a fix for 32-bit windows? |
CI showed 512 still faults on windows: msvc's default stack is 1MB, which is not enough to reach the limit, so deeply nested input dies before the parser can report anything. Picking a limit that does fit in 1MB is not really an option. It would have to be somewhere under 256, and real modules need more than that -- round-tripping sqlite needs 320 -- so it would start rejecting input that parses fine today on Linux and macOS. Asking for the 8MB those platforms already give us instead. This is the same change WebAssembly#2748 makes for the same reason; happy to drop it here if that lands first.
Use MSVC 64-bit file APIs with shared stdio paths. Remove the redundant SeekFile and chunked IO helpers after checking the UCRT implementation. Guard non-MSVC seek offsets and add Windows x64 coverage above 2GB. Keep the upstream 8MB stack setting.
|
Updated the code and rewrote the PR description to match it. On the chunking question: I checked Microsoft's published UCRT source package. On the platform question: the reported failure and the earlier successful 2,978,116,509-byte WAT conversion were both on Windows x64, not a 32-bit Windows process. MSVC's I also merged current Local warnings-as-errors builds and all 137 unit tests pass. All 17 GitHub checks on the final commit |
|
@sbc100 The revisions are ready for another review at The earlier stack-size and All 17 GitHub checks passed, including the Windows x64 regression that reads and patches a file above 2GB. Could you take another look when convenient? |
zherczeg
left a comment
There was a problem hiding this comment.
It is a bit of unclear the target of this patch for me. Do we need to process > 4GB files? Is this a real use case?
|
@zherczeg Yes, this is a real use case: I have used input files larger than 4GB, and that workload is how I encountered the bug. The previously documented 2,978,116,509-byte sample is an earlier validation example, not the largest input I have needed to process. The target is large-file IO on Windows/MSVC, including a 64-bit process, where the default file-size and seek/tell interfaces still use 32-bit sizes or offsets. This patch is not a streaming-parser redesign and does not promise that a 32-bit process can hold a multi-GB input in memory. The follow-up is now pushed as I added a sparse-file seek/backpatch regression above 4GB that does not allocate a 4GB buffer. The existing whole-file read regression stays just above the signed 32-bit boundary to limit its memory cost. The larger real-world input is a reported use case, not a claim that I have rerun that input in CI. Windows x64 CI passed the build, all 138 unit tests, C API tests, and full test suite. Both the >4GB seek/backpatch regression and the revised 2GB+ read regression ran successfully, rather than being skipped. Other checks are still completing. @sbc100 The testing follow-up is ready for another look. |
|
Can you suggest a short summary for the commit message for this change, either by updating the PR description of posting your proposed commit message here as a comment. |
|
@sbc100 Proposed commit message (also added to the PR description): I have synchronized upstream All 17 checks on the synchronized head Windows x64 CI passed the complete job. Its logs confirm all 138 unit tests passed and both large-file regressions actually ran successfully, not skipped: >4GB seek/backpatch in 5ms and 2GB+ whole-file read in 1112ms. The synchronized head also passed the local macOS warnings-as-errors build, unit tests, C API examples, and full test suite. |
Proposed commit message
Problem
Windows/MSVC builds can fail to read large WAT inputs because a 64-bit process does not make
long,fseek,ftell, or the default_statfile-size fields 64-bit. Actual use of inputs larger than 4GB exposed this bug. The earlier 2,978,116,509-byte business sample was a validation example, not the largest input used.This fixes file I/O, not the parser's whole-file memory requirements. It does not introduce a streaming parser or promise arbitrary multi-GB buffers in a 32-bit process.
Changes
_stat64,_fseeki64, and_ftelli64incommon.cc; retain the file-size return type and reject sizes that cannot fit insize_tbefore allocation._fseeki64instream.ccwithout an extraSeekFilehelper. On non-MSVC builds, check the actual seek offset againstLONG_MAXbeforefseek.fread/fwritepaths. Microsoft's published UCRT source already bounds low-level transfers internally; an_readlimit is not a limit on a wholefreadcall.ReadFilepath.mainthroughb835f1cein merge commitc28985b4. The upstreamByteSpanAPI and unified 8MB stack reserve from #2815 are retained; there is no separate stack-size change in this PR.Validation
2d6c0725, including CI and CIFuzz.2d6c0725included a warnings-as-errors build, all 138 unit tests, roundtrip tests, and C API examples. Deliberately narrowing the seek offset to 32 bits failed the >4GB regression; the correct implementation passed. That diagnostic modification was not committed.c28985b490142d276c1fae6ab9a53b77126000d1: CI and CIFuzz both completed successfully, including the s390x check. There are no failed or pending checks on this head.c28985b4also passed a local macOS Debug warnings-as-errors build, all 138 unit tests, C API examples, and the full test suite. For the wasm2c compiler, the local run explicitly set the Command Line Tools SDK path; no source change was needed. The generated-file/working-tree check was clean.c28985b4passed its complete job. Logs confirm all 138 unit tests passed and both large-file regressions ran successfully, not skipped: >4GB seek/backpatch in 5ms and 2GB+ whole-file read in 1112ms.Earlier Windows x64 business-sample validation was on
180b6bc7: a 2,978,116,509-byte WAT input produced a 92,039,608-byte wasm output with exit code 0 and an 8MB stack reserve. That is historical evidence, not a rerun of the current revision or the reported >4GB real-world input.The MSVC 64-bit file interfaces are also available in 32-bit builds, but
size_tand whole-file memory limits still apply. No new Windows x86 execution result is claimed. Linux/UNIXfseekoand_FILE_OFFSET_BITS=64portability work is left for a separate follow-up, as suggested in review.