Modify

Opened 3 years ago

Closed 3 years ago

#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 Changed 3 years ago by Jpm

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 Changed 3 years ago by Jpm

  • Owner set to Jpm
  • Status changed from new to assigned

fix sent to Jon

comment:3 Changed 3 years ago by Jon

  • Milestone set to 3.3.15.4
  • Owner changed from Jpm to Jon
  • Resolution set to Fixed
  • Status changed from assigned to closed

Fixed by revision [12561] in version: 3.3.15.4

Guidelines for posting comments:

  • You cannot re-open a ticket but you may still leave a comment if you have additional information to add.
  • In-depth discussions should take place on the forum.

For more information see the full version of the ticket guidelines here.

Add Comment

Modify Ticket

Action
as closed The owner will remain Jon.
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.