Modify

Opened 14 years ago

Closed 14 years ago

Last modified 14 years ago

#2085 closed Bug (No Bug)

DllStructGetData crash with char array

Reported by: anonymous Owned by:
Milestone: Component: AutoIt
Version: 3.3.8.0 Severity: None
Keywords: Cc:

Description

DllStructGetData seems to verify or fetch whole data of structs created from string pointers. Comment out the first region to see a work-around.

Local $sA = "String A", $xA = StringToBinary($sA) & "00"
Local $sB = "String B", $xB = StringToBinary($sB) & "00"
; A binary string that contains the null delimited strings
Local $xAB = $xA & StringTrimLeft($xB, 2)

; Verify data
ConsoleWrite($xA & @LF & $xB & @LF & $xAB & @LF & @LF)

Local $tBuffer = DllStructCreate("byte[" & BinaryLen($xAB) & "]")
Local $pBuffer = DllStructGetPtr($tBuffer)
DllStructSetData($tBuffer, 1, $xAB)

; Verify data
ConsoleWrite(DllStructGetData($tBuffer, 1) & @LF)

#region >_<
; Create a dllstruct used for getting strings of max size
Local $tPath = DllStructCreate("char[1048576]", $pBuffer)
ConsoleWrite(DllStructGetData($tPath, 1) & @LF) ; crash
#endregion

#region Q(0_0 Q)
Local $iSize = _StrLen($pBuffer)
ConsoleWrite($iSize & @LF)
Local $tPath = DllStructCreate("char[" & $iSize & "]", $pBuffer)
ConsoleWrite(DllStructGetData($tPath, 1) & @LF)
#endregion

Func _StrLen(Const $pString)
	Local $aResult = DllCall("msvcrt.dll", "int:cdecl", "strlen", "ptr", $pString)
	Return $aResult[0]
EndFunc

P.S.
I don't need an array that is that big. It happens even with smaller arrays.

P.S. 2
If, for some reason, it doesn't crash even with 1 MB, try a bigger one.

Attachments (0)

Change History (2)

comment:1 by trancexx, 14 years ago

Resolution: No Bug
Status: newclosed

When structure is created at address specified by the user (your $pBuffer) AutoIt doesn't do any memory allocation. It assumes the user is smart enough to check, or to know in advance how big the pointed memory space is. It's you who decided to create bad structure in first place.

This is not a bug. It's just careless bad programmer you.

in reply to:  1 comment:2 by anonymous, 14 years ago

Replying to trancexx:

When structure is created at address specified by the user (your $pBuffer) AutoIt doesn't do any memory allocation. It assumes the user is smart enough to check, or to know in advance how big the pointed memory space is. It's you who decided to create bad structure in first place.

This is not a bug. It's just careless bad programmer you.

Bad programmer.... :)

Modify Ticket

Action
as closed The ticket will remain with no owner.

Add Comment


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