Jump to content


Photo

(FIxed) IniRead crashes L when no section given


  • Please log in to reply
12 replies to this topic

#1 RaptorX

RaptorX
  • Members
  • 718 posts

Posted 01 February 2012 - 08:46 PM

Hi guys,

well as the title says if you omit the section option but still provide a key option Autohotkey L crashes which in general shouldnt be, i would expect an error or any other type of message.

iniread, var, test.ini,,new ; this crashes L (ansi & unicode), file enconding is ansi
msgbox % var


#2 Lexikos

Lexikos
  • Administrators
  • 8853 posts

Posted 06 February 2012 - 11:46 AM

With this INI file, it returned the word "ERROR":
[section]
key=value
With this INI file, it returned the value "123":
[]
new=123
So you see, an empty section name is also valid.

And no, it did not crash.

#3 Guests

  • Guests

Posted 06 February 2012 - 06:59 PM

And no, it did not crash.

I can make it crash too! :D or :cry: depending how you look at it. This test script makes it crash. I think.
ini=
(
[2]
var=hello
)
filedelete, test.ini
fileappend, %ini%, test.ini

iniread, var, test.ini,,new ; this crashes L (ansi & unicode), file enconding is ansi
msgbox % var

v1.1.05.06

#4 Lexikos

Lexikos
  • Administrators
  • 8853 posts

Posted 06 February 2012 - 09:29 PM

Nope, that didn't crash either. It just set var to the default value, as it was supposed to.

I think.

Does it crash or not?

#5 Guests

  • Guests

Posted 06 February 2012 - 09:54 PM

Yes, I get a Microsoft error window with:

AutoHotkey_L has encountered a problem and needs to close. We are sorry for the inconvenience.
If you were in the middle of something, the information you were working on might be lost.
We have created an error report that you can send to us. We will treat this report as confidential and anonymous.
To see what data this error report contains...

Error report contains:

AppName: autohotkey.exe AppVer: 1.1.5.1 ModName: ntdll.dll
ModVer: 5.1.2600.6055 Offset: 000120e6

Using Windows XP, so that might help.

#6 JSLover

JSLover
  • Members
  • 920 posts

Posted 07 February 2012 - 05:19 AM

Error report contains:

AppName: autohotkey.exe AppVer: 1.1.5.1

...version 1.1.5.1 is not 1.1.05.06. I still have version 1.1.05.01 & it does not crash (with that exact test script).

But there's seems to be ALOT of confusion going on...(or at least, I'm confused)...so lets get real specific...
[*:3jl0mrjf]What OS?
[*:3jl0mrjf]Which version of AutoHotkey?
[*:3jl0mrjf]Is AutoHotkey ANSI or Unicode?
[*:3jl0mrjf]Is the problem ini file ANSI or Unicode?...some of that is covered above, in pieces (& by different people?), but if everyone who CAN get the crash would fill out the above info, that would help.

Also, if you CAN get the crash, reboot your computer & try again...sometimes Windows gets "irritated" & will continue to crash until a reboot (cuz of memory corruption {or something} from a previous crash).

#7 just me

just me
  • Members
  • 1175 posts

Posted 07 February 2012 - 05:30 AM

ini=
(
[2]
var=hello
)
filedelete, test.ini
fileappend, %ini%, test.ini

iniread, var, test.ini,,new ; this crashes L (ansi & unicode), file enconding is ansi
msgbox % var

reports ERROR when run as script and crashes when run as exe.
AHK 1.1.05.06 (U32), Win Vista 32, "test.ini" encoding is ANSI.

filedelete, test.ini
iniwrite, hello, test.ini, 2, var
iniread, var, test.ini,,new ; this crashes L (ansi & unicode), file enconding is ansi
msgbox % var
crashes when run as script and crashes when run as exe.
AHK 1.1.05.06 (U32), Win Vista 32, "test.ini" encoding is UNICODE.

#8 JSLover

JSLover
  • Members
  • 920 posts

Posted 07 February 2012 - 06:19 AM

crashes when run as script and crashes when run as exe.

...CONFIRMED...this script does crash...

FileDelete, test.ini
IniWrite, hello, test.ini, 2, var
IniRead, var, test.ini, , test

msgbox, var(%var%)
...on...
[*:wqw9do6m]OS - WinXP 32-bit
[*:wqw9do6m]AutoHotkey - 1.1.05.01 Unicode AND 1.1.05.06 Unicode
[*:wqw9do6m]ini encoding: Unicode BOM
[*:wqw9do6m]Crashes when compiled or not...& also on...
[*:wqw9do6m]OS - WinXP 32-bit
[*:wqw9do6m]AutoHotkey - 1.1.05.01 ANSI AND 1.1.05.06 ANSI
[*:wqw9do6m]ini encoding: ANSI
[*:wqw9do6m]Crashes when compiled or not
* however, I couldn't download the old ANSI version of Ahk2Exe (or more specifically, I couldn't download version 1.1.05.01 of "ANSI 32-bit.bin" to use in Ahk2Exe), then I found it in my installed dir of 1.1.05.01 -- why are old versions of Ahk2Exe (& the *.bins) not available?[/list]I cannot get the 1st script to crash, still testing.

#9 Lexikos

Lexikos
  • Administrators
  • 8853 posts

Posted 07 February 2012 - 07:41 AM

As far as I can ascertain, AutoHotkey is calling GetPrivateProfileString with valid parameters on a correctly-formed INI file, and the crash occurs within that function. Perhaps Microsoft did not anticipate empty section names, and only luck allows it to work some of the time. IniRead required a non-empty Section up until the parameter was made optional to support retrieving a list of section names. Since IniWrite requires Section to be non-blank, some additional validation for IniRead seems in order (expect it in the next release).

Thank you for your perseverence, and more importantly, for providing enough detail to reproduce the problem.

Edit: I may have found a simpler, better solution. Are any of you able to reproduce a crash using %A_Space% as the section name? Leading and trailing spaces in section names seem to be ignored, except when the section is being created. So A_Space matches [], [ ], etc. If a crash cannot be reproduced, I will add the following simple check in IniRead:
if (!*aSection)
			aSection = _T(" ");


#10 just me

just me
  • Members
  • 1175 posts

Posted 07 February 2012 - 09:21 AM

filedelete, test.ini
iniwrite, hello, test.ini, 2, var
iniread, var, test.ini,,new
msgbox % var
Crashes on Win XP SP3 (32) + AHK 1.1.05.02 (U32), compiled or not.
filedelete, test.ini
iniwrite, hello, test.ini, 2, var
iniread, var, test.ini, [color=red]%A_Space%[/color] , new
msgbox % var
Doesn't crash on Win XP SP3 (32) + AHK 1.1.05.02 (U32), compiled or not.

#11 RaptorX

RaptorX
  • Members
  • 718 posts

Posted 07 February 2012 - 05:24 PM

Confirmed this script crashes on both versions:
msgbox % a_ahkversion ; 1.1.05.06 ANSI & UNICODE
FileDelete, test.ini
IniWrite, hello, test.ini, 2, var
IniRead, var, test.ini, , test

msgbox, var(%var%)

While adding %a_space% on the parameter 'fixes' the issue.

Sorry for the lack of information on the OP... found the bug at 4am while rushing some code trying to go to sleep :roll:

and the messaging system from the site sucks... you guys had a whole conversation here and now i got the first msg saying that there was a reply :lol:

#12 Guests

  • Guests

Posted 07 February 2012 - 07:24 PM

Confirmed, adding A_space results in ERROR and not a crash.

#13 Lexikos

Lexikos
  • Administrators
  • 8853 posts

Posted 13 February 2012 - 11:44 AM

I had intended to include a fix in v1.1.06.00, but it slipped my mind.

This is the working solution I've come up with (the one I mentioned earlier didn't work for reasons explained below):
TCHAR	szEmpty[] = _T("");
[color=#888888]...[/color]
[color=green]		// An access violation can occur if the following conditions are met:
		//	1) aFilespec specifies a Unicode file.
		//	2) aSection is a [/color][color=red]read-only[/color][color=green] string, either empty or containing only spaces.
		//
		// Debugging at the assembly level indicates that in this specific situation,
		// it tries to write a zero at the end of aSection (which is already null-
		// terminated).
		//
		// The second condition can ordinarily only be met if Section is omitted,
		// since in all other cases aSection is writable.  Although Section was a
		// required parameter prior to revision 57, empty or blank section names
		// are actually valid.  Simply passing an empty writable buffer appears
		// to work around the problem effectively:[/color]
		if (!*aSection)
			aSection = szEmpty;