Modify

Opened 13 years ago

Closed 13 years ago

Last modified 13 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 follow-up: Changed 13 years ago by trancexx

  • Resolution set to No Bug
  • Status changed from new to closed

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.

comment:2 in reply to: ↑ 1 Changed 13 years ago by anonymous

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.... :)

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 ticket will remain with no owner.
Author


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

 
Note: See TracTickets for help on using tickets.