Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

integer truncation in truncate on Windows #24466

Closed
simonster opened this issue Nov 4, 2017 · 3 comments · Fixed by #24616
Closed

integer truncation in truncate on Windows #24466

simonster opened this issue Nov 4, 2017 · 3 comments · Fixed by #24616
Labels
bug Indicates an unexpected problem or unintended behavior io Involving the I/O subsystem: libuv, read, write, etc. system:windows Affects only Windows

Comments

@simonster
Copy link
Member

While ios_trunc accepts a size argument of type size_t, it calls _chsize, which takes a long (32-bit int on Windows), and it doesn't check for overflow. As a result, this fails:

open("some_file_name", "w") do f
    truncate(f, 2^31+1)
end

ios_trunc should probably be modified to use _chsize_s.

(Originally reported as JuliaIO/JLD2.jl#50.)

@simonster simonster added bug Indicates an unexpected problem or unintended behavior system:windows Affects only Windows io Involving the I/O subsystem: libuv, read, write, etc. labels Nov 4, 2017
@jaakkor2
Copy link
Contributor

jaakkor2 commented Nov 6, 2017

Looks like it used to be _chsize_s, but was changed to _chsize here https://github.com/JuliaLang/julia/pull/3011/files back in 2013 due to MinGW compilation problems.

If defined(__MINGW32__) continue to use _chsize, otherwise _chsize_s on Windows?

@vtjnash
Copy link
Member

vtjnash commented Nov 6, 2017

MinGW is long dead

@jaakkor2
Copy link
Contributor

Consequence of this bug: on Windows 64-bit files larger than 2 GB cannot be truncated. For example, JLD2-files are now limited to 2 GB size.

Looks like cygwin64/mingw64-x86_64 is used to compile the version downloadable at https://julialang.org/downloads/ . And looks like mingw64 has _chsize_s defined in mingw-w64/mingw-w64-crt/secapi/_chsize_s.c . But I do not find references to --enable-secure-api option in Julia code.

If we are targeting systems newer than Windows XP, _chsize_s should be ok, but I have no possibility to do testing now. Help wanted :)

vtjnash pushed a commit that referenced this issue Dec 9, 2017
Should allow files >2 GB to be truncated on Windows.

Fix #24466

Checking Windows 32bit build https://julialang-s3.julialang.org/bin/winnt/x86/0.6/julia-0.6.1-win32.exe, libgit2.dll already uses `_chsize_s`, so both 32bit and 64bit should be able to use `_chsize_s`.
evetion pushed a commit to evetion/julia that referenced this issue Dec 12, 2017
Should allow files >2 GB to be truncated on Windows.

Fix JuliaLang#24466

Checking Windows 32bit build https://julialang-s3.julialang.org/bin/winnt/x86/0.6/julia-0.6.1-win32.exe, libgit2.dll already uses `_chsize_s`, so both 32bit and 64bit should be able to use `_chsize_s`.
ararslan pushed a commit that referenced this issue Apr 26, 2018
Should allow files >2 GB to be truncated on Windows.

Fix #24466

Checking Windows 32bit build https://julialang-s3.julialang.org/bin/winnt/x86/0.6/julia-0.6.1-win32.exe, libgit2.dll already uses `_chsize_s`, so both 32bit and 64bit should be able to use `_chsize_s`.

Ref #24616
(cherry picked from commit ff045af)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Indicates an unexpected problem or unintended behavior io Involving the I/O subsystem: libuv, read, write, etc. system:windows Affects only Windows
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants