Modify

#3789 closed Bug (Fixed)

Fileread() returns empty string when variable > 2GB

Reported by: Exit Owned by: Jon
Milestone: 3.3.15.4 Component: AutoIt
Version: 3.3.14.0 Severity: None
Keywords: Cc:

Description

2GB is the maximum variable size in Autoit.
If this size is reached with Fileread() due to UTF8 2 byte processing, then @extended shows 1073741823 read bytes, but the resulting string is empty.
I think Fileread() should show @error > 0 .
Here a reproducer:

; proof 2GB Variable fileread Error

#AutoIt3Wrapper_UseX64=y
#include <String.au3>
$sTestDir = @TempDir & "\~Test~\"
DirCreate($sTestDir)
FileDelete($sTestDir & "*.txt")
ShellExecute($sTestDir)

OnAutoItExitRegister(_Exit)
Func _Exit()
	ToolTip("")
	MsgBox(64 + 262144, Default, "Check SciTE output to verify Fileread() error." & @LF & @LF & "Then press OK to exit.", 0)
	DirRemove($sTestDir, 1)
	Sleep(500)
	WinClose("[TITLE:" & StringLeft($sTestDir, 3) & "; CLASS:CabinetWClass]")
EndFunc   ;==>_Exit

$iLength = 1024 * 1024 * 1024    ;  1 Gigabyte
$s1GB = _StringRepeat("-", $iLength)
$iLength -= 3

For $i = 1 To 2
	ToolTip("Writing Record #" & $i & ". This takes a while. Stay tuned.")
	Beep(1000, 100)
	$iLength += 1
	$hFileHandle = FileOpen($sTestDir & $i & ".txt", 2)
	$sInitData = StringLeft($i & $s1GB, $iLength)
	FileWrite($hFileHandle, $sInitData)
	FileSetPos($hFileHandle, 0, 0)
	$sReadData = FileRead($hFileHandle)
	ConsoleWrite(@LF & "Fileread $i:" & $i & " Error: " & @error & " Extended: " & @extended & @LF & "    Datalen: " & StringLen($sInitData) & @LF & "ReadDatalen: " & StringLen($sReadData) & @LF & "ReadData(first 10 Bytes): >" & StringLeft($sReadData, 10) & "< " & @LF & "Stringcompare Result: " & (StringCompare($sInitData, $sReadData, 1) ? "NOT" : "") & " equal" & @LF & @LF)
	ToolTip("")
	If StringCompare($sReadData, $sInitData, 1) Then Exit MsgBox(16 + 262144, Default, "Compare Error. I=" & $i, 0)
	FileClose($hFileHandle)
Next

and here the resulting SciTE output:

Fileread $i:1 Error: 0 Extended: 1073741822
    Datalen: 1073741822
ReadDatalen: 1073741822
ReadData(first 10 Bytes): >1---------< 
Stringcompare Result:  equal


Fileread $i:2 Error: 0 Extended: 1073741823
    Datalen: 1073741823
ReadDatalen: 0
ReadData(first 10 Bytes): >< 
Stringcompare Result: NOT equal

Attachments (0)

Change History (3)

comment:1 by Jpm, on Dec 10, 2020 at 1:33:40 PM

In fact the situation come frome the fact that AutoIt cannot detect on the file open in output that the data are in ANSI format.
So just add 512 ($FO_ANSI) in the FileOpen mode.
It look like Windows as some limitation on the data length to convert from UTF8 to Unicode.
I will try to propose a go around without modifying the FileOpen mode.

comment:2 by Jpm, on Dec 10, 2020 at 3:09:41 PM

Owner: set to Jpm
Status: newassigned

fix sent to Jon

comment:3 by Jon, on Jun 11, 2021 at 1:45:15 PM

Milestone: 3.3.15.4
Owner: changed from Jpm to Jon
Resolution: Fixed
Status: assignedclosed

Fixed by revision [12561] in version: 3.3.15.4

Modify Ticket

Action
as closed The owner will remain Jon.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.