Simple caret (^) at end of Windows batch file consumes all memory
Thoughts
The cause of this (from my understanding) is due to the cmd interpreter looking for a character to escape since the ^
is the batch escape character. Instead of properly identifying the end of file eof
in this scenario, cmd just keeps looping and initializing something while looking for the character to escape.
Reproduced on Windows 8 Pro (64) with cc^^^
(Multiple carets used to speed up the leak).
Trials
cc^
infinite loop and leaks very slowly.
cc^^
crashes with normal invalid command error.
cc^^^
infinite loop and leaks faster.
cc ^
infinite loop and leaks very slowly.
cc ^^
crashes with normal invalid command error.
cc ^^^
infinite loop and leaks faster.
cc"^
crashes with normal invalid command error.
cc"^^
crashes with normal invalid command error.
cc"^^^
crashes with normal invalid command error.
Notes
- Only infinite loop and leaks when carets
^
are used literally (outside of quotations). When quotation added the script crashes with standard invalid command error. - Only infinite loop and leaks when batch file is encoded as UTF-8 or ASCII. When UTF-16, the script crashes with standard invalid command error.
- Must be an odd number of carets as to not escape the last caret.
Precautions
- Make sure no batch scripts end with a caret
^
(0x5E) or at least an odd number of carets. - Or encode them in UTF-16.