Skip to content

Commit

Permalink
Fix overflow in File#read_at for large offsets on Windows (#14708)
Browse files Browse the repository at this point in the history
Allows `File#read_at` to work for offsets at 2 GiB or larger.
  • Loading branch information
HertzDevil authored Jun 14, 2024
1 parent 1a6686a commit 7a183b3
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/crystal/system/win32/file_descriptor.cr
Original file line number Diff line number Diff line change
Expand Up @@ -259,8 +259,8 @@ module Crystal::System::FileDescriptor
handle = windows_handle(fd)

overlapped = LibC::OVERLAPPED.new
overlapped.union.offset.offset = LibC::DWORD.new(offset)
overlapped.union.offset.offsetHigh = LibC::DWORD.new(offset >> 32)
overlapped.union.offset.offset = LibC::DWORD.new!(offset)
overlapped.union.offset.offsetHigh = LibC::DWORD.new!(offset >> 32)
if LibC.ReadFile(handle, buffer, buffer.size, out bytes_read, pointerof(overlapped)) == 0
error = WinError.value
return 0_i64 if error == WinError::ERROR_HANDLE_EOF
Expand Down

0 comments on commit 7a183b3

Please sign in to comment.