6 Replies Latest reply on Nov 17, 2013 3:00 PM by SlavaBuck

    ESTK string bug [CS5, CS5.5]

    cweger79 Level 1

      Hi all,


      Consider this JavaScript:


      var s = String.fromCharCode(65, 66, 67, 68, 69); 
      $.writeln("string len=" + s.length);
      for (var i=0; i < s.length; i++) {
        $.writeln("#" + i + " = " + s.charCodeAt(i));


      When run, this produces this output in the JavaScript console:

      string len=5
      #0 = 65
      #1 = 66
      #2 = 67
      #3 = 68
      #4 = 69


      However, if I change one of the character codes to zero, so for example:


      var s = String.fromCharCode(65, 66, 0, 68, 69)


      Then the script runs once. After running, ESTK is locked up. I can mouse around and select menus, etc., but the menus don't do anything. Everything is frozen and I have to either quit or sometimes force-quit ESTK.


      This happens to me on Windows 7 with ESTK (CS5) and on Mac 10.6.6 with ESTK (CS5.5).


      I get the fact that odd things might happen to a string containing a null byte, but I would expect in the worst case to have the string output terminate prematurely, not have the whole IDE hang.


      Is this something that's been noticed before (sorry if it has, forum searching is a big wonky these days)? Is there anything I can do about it?


      Thanks in advance for suggestions.



        • 1. Re: ESTK string bug [CS5, CS5.5]
          cweger79 Level 1

          Actually, never mind. I've done some web surfing and discovered that JavaScript and binary data do not, in general, get along very well at all.


          There's some hope for browsers -- for example, Mozilla has typed arrays (https://developer.mozilla.org/en/JavaScript_typed_arrays) -- but old school JavaScript/ECMAScript like the version in ESTK just won't work with this.


          So I'll go off and do what I need to do in C.


          HOWEVER, my bug report still stands. I don't think the IDE should crash when encountering this situation.




          • 2. Re: ESTK string bug [CS5, CS5.5]
            John Hawkinson Level 5

            The ESTK does weird things if the Javascript engine crashes. Certainly that shouldn't happen, and you should submit a bug report, either through a support channel or to adobe.com/go/wish. But I think the bigger issue is the Javascript engine crashing.


            That said, I suspect you're mostly fine with binary data in strings as long as you don't call certain kinds of functions. Somehow I'm not surprised that the fromCharCode methods kills everything...

            • 3. Re: ESTK string bug [CS5, CS5.5]
              John Hawkinson Level 5

              However, I am a bit more disturbed that this program causes a similar hang:


              //var s = String.fromCharCode(65, 66, 67, 68, 69);
              var s= "\u0041\u0042\u0000\u0044\u0045"; 
              $.writeln("string len=" + s.length);
              for (var i=0; i < s.length; i++) {
                //$.writeln("#" + i + " = " + s.charCodeAt(i));


              So, it's not even necessary to index into the string to cause the problem, nor is it the fromCharCode or charCodeAt methods.

              • 4. Re: ESTK string bug [CS5, CS5.5]
                Marc Autret Level 4

                Same result in WinXP + ESTK CS5.


                Just needed to inject a \x00 in a literal string to crash ESTK.


                Minimal code tested:


                var s= "\x41\x42\x00\x44\x45";


                Result in the data browser: s is undefined —while ESTK CS4 displays 'AB'.




                • 5. Re: ESTK string bug [CS5, CS5.5]
                  cweger79 Level 1

                  "AB" is what I would expect, assuming the JavaScript engine is using C-style null-terminated strings. I still pine for binary data, though.


                  • 6. Re: ESTK string bug [CS5, CS5.5]

                    I'm found only one safe way to use binary data in strings with ESTK:

                    Do not use a direct assignment binary data to any variable in the body of the script, but you can get its as function result or put it as a function argument directly:

                    var s= "\x41\x42\x00\x44\x45"; // cause problems


                    var s = function() { return "\x41\x42\x00\x44\x45....." }; // not cause problems!!!

                    and then use s() anywhere;


                    var s = ScriptUI.newImage ("\x41\x42\x00\x44\x45....."); // for embedding image...



                    sorry for my english, I use google translate something where