Repository navigation
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. |
|
|
||
| #if !COMPILER_IS_MSVC | ||
| TEST(FileStream, RejectUnrepresentableSeekOffset) { | ||
| std::unique_ptr<FILE, FileCloser> file(tmpfile()); |
There was a problem hiding this comment.
I guess maybe on linux/UNIX we should use fseeko and set _FILE_OFFSET_BITS=64? But that can be followup of course
|
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. |
Problem
Windows x64 builds can fail to read WAT files larger than 2GB (
value too large/unable to read file). A 64-bit process does not make MSVC'slong,fseek,ftell, or the default_statfile-size fields 64-bit.This is motivated by actual use of input files larger than 4GB, which exposed the bug. The earlier documented 2,978,116,509-byte input is a validation sample, not the largest real-world input. The patch repairs file IO; it does not redesign the parser to stream inputs or reduce its whole-file memory requirements.
Changes
stat,fseek, andftellto_stat64,_fseeki64, and_ftelli64incommon.ccunder MSVC. Infer the file-size type fromftelland reject sizes that cannot fit insize_tbefore allocating.fseekto_fseeki64instream.cc, using the same seek call across platforms. Remove the extraSeekFilehelper. On the non-MSVC path, check the actual seek offset (at) againstLONG_MAXbefore passing it tofseek.stdio/fread.cppandstdio/fwrite.cpp. The low-level_readlimit does not establish a limit on an entirefreadcall. This revision keeps the regularfread/fwritepaths shared across platforms.mainand adapt to theByteSpanAPI. The 8MB stack reserve inwabt_executableis already upstream via #2815, so this PR no longer contains a separate stack-size change.Validation
2d6c0725passed the complete Windows x64 CI job, including 138 unit tests, C API tests, and the full test suite. The >4GB seek/backpatch test ran successfully in 5ms and the revised 2GB+ whole-file read test in 1131ms; neither was skipped.cbe0a753(CI run). Checks for the follow-up revision will be reported separately.wat2wasm,wasm2wat, andwabt-unittests, with warnings treated as errors.ReadFileintentionally allocates a whole-file buffer; it therefore needs roughly 2GB of memory. It now uses a narrow filename in the current test directory and stdio for file IO, with Windows APIs used only to enable sparse storage. Exclusive file creation prevents overwriting an existing file.FileStream, then loaded it throughReadFileand verified its size and contents. It ran successfully (not skipped), exercising 64-bit file metadata, seek, tell, and a single application-levelfreadabove 2GB. It requires about 2GB of memory and is restricted to MSVC x64.Earlier Windows x64 business-sample validation was performed on commit
180b6bc7: a 2,978,116,509-byte WAT file produced a 92,039,608-byte wasm file with exit code 0 and an 8MB stack reserve. That result predates this simplified revision; it is not a new rerun of the business sample.This fixes large-file IO on Windows x64. It does not promise that a 32-bit process can hold arbitrary multi-GB inputs in memory, or that the parser's whole-file memory requirements have changed.
The MSVC CRT
_stat64,_fseeki64, and_ftelli64interfaces are also available to 32-bit builds; their 64-bit file sizes/offsets are independent of pointer size. Thesize_tbound remains, so a 32-bitReadFilebuffer cannot represent an input above 4GB. The multi-GB read test is limited to MSVC x64; this revision does not claim a new Windows x86 execution result.