fs functions: Support file positions and sizes above 2 GB - #404
Open
PTR-inc wants to merge 1 commit into
Open
Conversation
readSync, fs.read, write, writeSync and createReadStream held the position in a 32-bit int, so anything past 2 GB silently did nothing. Add Duktape_GetInt64PropertyValue() for the 64-bit property, and 64-bit seeks. Duktape_GetIntPropertyValue() uses it too, fixing NaN, which returned 0 rather than the defaultValue. readFileSync() now refuses a file too large for a Duktape buffer instead of a truncating cast, returns the bytes actually read, and runs under duk_safe_call so the FILE* is closed when it throws. Built with -D_FILE_OFFSET_BITS=64 so off_t and struct stat are 64-bit on 32-bit targets. Also the dynamic buffer for readFileSync() now grows to 8MB increments instead of the 1024 bytes to reduce the amount of re-allocations.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
readSync, fs.read, write, writeSync and createReadStream held the position in a 32-bit int, so anything past 2 GB silently did nothing.
Add Duktape_GetInt64PropertyValue() for the 64-bit property, and 64-bit seeks. Duktape_GetIntPropertyValue() uses it too, fixing NaN, which returned 0 rather than the defaultValue.
readFileSync() now refuses a file too large for a Duktape buffer instead of a truncating cast, returns the bytes actually read, and runs under duk_safe_call so the FILE* is closed when it throws.
Built with -D_FILE_OFFSET_BITS=64 so off_t and struct stat are 64-bit on 32-bit targets.
Also the dynamic buffer for readFileSync() now grows to 8MB increments instead of the 1024 bytes to reduce the amount of re-allocations.
Please follow this checklist to avoid unnecessary back and forth (click to expand)
I understand that I am responsible for and able to explain every line of code I submit.
the impact on platforms and architectures I could not test.
modules/, I re-embedded them so the compiled-in copies inmicroscript/ILibDuktape_Polyfills.cmatch (the agent runs the embedded copies, not the files on disk)..mshoptions table in readme.md.Testing
Tested on mac arm64/x64, linux x86/x64 and windows x86/x64