Announcement

Collapse
No announcement yet.

nsJSON plug-in

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • #16
    nsJSON::Serialize crashes nsis installer with recent stable chrome default Preferences, which contain a very long (~66 KBytes) `variations_seed` string parameter.

    Test case:
    Fresh install of google chrome (33.0.1750.154) which contain `variations_seed` parameter.
    code:
    nsJSON::Set /file "$Prefs"
    nsJSON::Serialize /format /file "$Prefs"

    I'm using ANSI NSIS v2.46 with nsJSON 1.0.1.0.

    Preferences sample:


    deleting `variations_seed` before serializing workarounds this, but is ugly
    code:
    nsJSON :: Delete `variations_seed` /end

    Comment


    • #17
      PHP Code:
      nsJSON::Set /file "$Prefs"
      nsJSON::Serialize /format /file "$Prefs
      with following json:
      PHP Code:
      {
         
      "selectfile": {
            
      "last_directory""E:\\"
         
      },
         
      "session": {
            
      "restore_on_startup_migrated"true,
            
      "startup_urls_migration_time""13037468179710507"
         
      }

      saves broken json:
      PHP Code:
      {
          
      "selectfile": {
              
      "last_directory""E:\\"
         
      },
         
      "
          }

      Comment


      • #18
        Originally Posted by maliktous View Post
        PHP Code:
        {
           
        "selectfile": {
              
        "last_directory""E:\\"
           
        },

        It take it the plugin escapes the last quote, but wouldn't you have to escape the backslash as well?
        NSIS IDE for Atom | NSIS for Visual Studio Code | NSIS for Sublime Text | NSIS.docset

        Comment


        • #19
          Originally Posted by Yathosho View Post
          It take it the plugin escapes the last quote, but wouldn't you have to escape the backslash as well?
          "E:\\" should end up as "E:\", there is no escaped quote because that double backslash was already used to create a backslash
          IntOp $PostCount $PostCount + 1

          Comment


          • #20
            Originally Posted by Yathosho View Post
            It take it the plugin escapes the last quote, but wouldn't you have to escape the backslash as well?
            1. It is a standart Google Chrome Preferences, so it is a valid json. I did not create it manually. I just read it, add my values, then save it.
            2. Python parses it correctly:
            PHP Code:
            cat test.json
            {
               
            "selectfile": {
                  
            "last_directory""E:\\"
               
            },
               
            "session": {
                  
            "restore_on_startup_migrated"true,
                  
            "startup_urls_migration_time""13037468179710507"
               
            }
            }
            >>> 
            f=open("test.json")
            >>> 
            import json
            >>> json.load(f)
            {
            u'selectfile': {u'last_directory'u'E:\\'}, u'session': {u'restore_on_startup_migrated'Trueu'startup_urls_migration_time'u'13037468179710507'}} 

            Comment


            • #21
              Originally Posted by Anders View Post
              "E:\\" should end up as "E:\", there is no escaped quote because that double backslash was already used to create a backslash
              ah, of course. you're right
              NSIS IDE for Atom | NSIS for Visual Studio Code | NSIS for Sublime Text | NSIS.docset

              Comment


              • #22
                Originally Posted by maliktous View Post
                nsJSON::Set /file "$Prefs"
                nsJSON::Serialize /format /file "$Prefs"
                with following json:
                saves broken json:
                workaround (should be used before Set /file ):
                PHP Code:
                Push `\\"`          # text to be replaced
                Push `"`            # replace with
                Push all            # replace all occurrences
                Push all            # replace all occurrences
                Push ${PrefsFile}   # file to replace in
                Call AdvReplaceInFile 

                Comment


                • #23
                  I will try to look at the issues this weekend.

                  Stu

                  Comment


                  • #24
                    1.0.1.1 - 29th March 2014
                    * Fixed incorrect handling of escape character (\).
                    Originally Posted by maliktous View Post
                    nsJSON::Serialize crashes nsis installer with recent stable chrome default Preferences, which contain a very long (~66 KBytes) `variations_seed` string parameter.
                    I could not reproduce this with the new build so it may be fixed. The full output string (66224 bytes) is correctly written to the output file for both the ANSI and Unicode versions. No memory access violations were caught in the debugger either.

                    Stu

                    Comment


                    • #25
                      I can confirm that there is still a problem. The problem happens when the data is >64KB. It doesn't always crash, though, because it's corrupting the heap which might or might not result in a crash.

                      The source of the problem is that in the Serialize function, you allocate 65536 bytes for pszArg:
                      code:
                      PTCHAR pszArg = (PTCHAR)LocalAlloc(LPTR, sizeof(TCHAR) * 65536);
                      ...and later you are using this buffer to store the serialized string:
                      code:
                      bOK = JSON_Serialize(g_root, pszArg, bIsFile, bAsUnicode, bFormat);
                      There is no length check taking place anywhere.

                      Comment


                      • #26
                        I will work on a fix to automatically increase the buffer size this weekend.

                        Stu

                        Comment


                        • #27
                          New version:
                          1.0.1.2 - 12th July 2014
                          * Fixed crash on serialization to file for node values larger than 64KB.
                          * Fixed crash on serialization to stack for JSON larger than NSIS_MAX_STRLEN. The JSON will now be truncated.
                          The file serialization doesn't use any temporary buffer any more (it just writes directly to the file) so no reallocation was necessary.

                          Stu

                          Comment


                          • #28
                            1.0.1.2 crashes if JSON file starts with Byte order mark

                            It seems that `nsJSON::Set /file $JSON` works but the next `nsJSON::Set` crashes installer.

                            I don't know if json can contain BOM, so it is just for your attention, but I guess, at least, it should not crash.

                            --- "Bad" 2014-09-05 15:53:16.000000000 +0300
                            +++ "Good" 2014-09-05 15:53:16.000000000 +0300
                            @@ -1,4 +1,4 @@
                            -<U+FEFF>{
                            +{
                            "test": {
                            Attached Files

                            Comment


                            • #29
                              New version:
                              1.0.1.3 - 18th October 2014
                              * Added UTF-16LE BOM, UTF-16BE BOM and UTF-8 signature detection for input files (with UTF-16BE conversion to UTF-16LE).
                              * Fixed formatting errors for the Serialize function.
                              * Fixed closing bracket or curly brace not being included on Serialize to stack when not using /format.
                              This should resolve the crash for files with UTF-8 signatures.

                              My next task is to add HTTP GET/PUT/POST support for use with REST.

                              Stu

                              Comment


                              • #30
                                nsJSON does not support comment

                                Hi,
                                I am trying to use nsJSON plug-in and just find out that comment '//' does disturb somehow the parser, and break the reading of any node inside the file...
                                I'll temporally avoid using comment until I find a proper solution!
                                Cheers,
                                Pascal

                                Comment

                                Working...
                                X
                                😀
                                🥰
                                🤢
                                😎
                                😡
                                👍
                                👎