Windows批处理文件结束处的简单插入符号(^)会占用所有内存 [英] Simple caret (^) at end of Windows batch file consumes all memory

查看:330
本文介绍了Windows批处理文件结束处的简单插入符号(^)会占用所有内存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个相对较短的简单批处理文件消耗了Windows 7(x64)上的所有可用内存。这是怎么回事?



 任何无效命令,你喜欢这里^ 

显然具有必要的前提条件:




  • 插入符 ^ 是文件中的最后一个东西,脚本不以换行符结尾

  • 插入符前面至少有2个空格或字符,例如如果下面的点代表空格,内存泄漏将不会被触发。^ ,而这个将 ... ^
  • ,消耗2.9GB,仍然以稳定的速度攀升:





    如果你要试验这个,确保你可以得到关闭窗口[X]控件或任务管理器或过程浏览器启动,准备好 Ctrl- C Ctrl-Break Alt-F4 没有效果。



    出现多个插入符号会导致内存使用率增加得更快。我第一次遇到这种情况时,在1或2分钟内没有足够的内存可以执行像 Alt-Tab 这样的简单操作,甚至3个手指致敬 Ctrl-Alt-Del 无效。

    解决方案

    思考



    原因(从我的理解)是由于cmd解释器寻找一个字符来逃避,因为 ^ 是批处理转义字符。在这种情况下,cmd只是继续循环并初始化某些东西,而不是正确地识别文件 eof 的结尾。



    使用 cc ^^^ (多克拉用于加速泄漏)在Windows 8 Pro(64)上重现。



    试验



    cc ^ 无限循环并且泄漏非常缓慢。



    cc ^^ 因正常的无效命令错误而崩溃。



    code> cc ^^^ 无限循环,泄漏更快。



    cc ^ 无限循环,并且泄漏非常缓慢。



    cc ^^ >

    cc ^^^ 无限循环,泄漏更快。



    cc^ 以正常的无效命令错误崩溃。



    cc code>正常无效命令错误导致崩溃。



    cc^^^ 错误。



    注释




    • 只有无限循环, $ c> ^ 字面使用(在引号外)。

    • 当批处理文件编码为 UTF-8 ASCII 时,只有无限循环和泄漏。 / strong>。当 UTF-16 时,脚本会与标准无效的命令错误一起崩溃。

    • 必须是奇数个克拉, >


    注意事项




    • 确保没有批处理脚本以 $ (0x5E)或至少奇数个克拉。

    • 或以UTF-16编码。


    This simple batch file in relatively short order consumes all available memory on Windows 7 (x64). What's going on? and what precautions can be taken to ward against it?

    any-invalid-command-you-like-here ^
    

    Apparently necessary preconditions to exhibit the effect:

    • the caret ^ is the very last thing in the file, and the script is not terminated with a newline
    • the caret is preceded by at least 2 spaces or characters, e.g. if the dots in the following represent spaces the memory leak will not be triggered .^, while this one will ..^ (just slowly)

    In this Process Explorer screen shot, the script had been running about 30 seconds, consumed 2.9GB, and was still climbing at a steady rate:

    If you're going to experiment with this, make sure you can get at the Close Window [X] control or have a Task Manager or Process Explorer fired up and ready as Ctrl-C, Ctrl-Break, Alt-F4 have no effect.

    It appears multiple carets will cause the memory usage to ramp up much more quickly. The first time I encountered this there wasn't enough memory available in 1 or 2 minutes to do simple things like Alt-Tab and even the 3 finger salute Ctrl-Alt-Del was ineffective. I had to hard power off the machine.

    解决方案

    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 carats 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 carats ^ 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 carats as to not escape the last carat.

    Precautions

    • Make sure no batch scripts end with a carat ^ (0x5E) or at least an odd number of carats.
    • Or encode them in UTF-16.

    这篇关于Windows批处理文件结束处的简单插入符号(^)会占用所有内存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆