Uploaded image for project: 'DMR'
  1. DMR
  2. DMR-48

Issue with json unicode parsing

XMLWordPrintable

    • Icon: Task Task
    • Resolution: Unresolved
    • Icon: Major Major
    • 1.6.0.Beta2
    • 1.5.1.Final
    • None

      There is an issue when parsing unicode strings when buffer is not holding enough chars. The code

      https://github.com/jbossas/jboss-dmr/blob/master/src/main/java/org/jboss/dmr/stream/JsonReaderImpl.java#L587

      It copy the buffer only if stringLength > 0. When stringLength == 0 the array should also be copied.

      The following simple test can show the issue:

       

      @Test
      public void testLongString() throws Exception {
          try (BufferedReader br = new BufferedReader(new FileReader(new File("longstr.json")))) {
              String jline = br.readLine();
              ModelNode json = ModelNode.fromJSONString(jline);
              assertNotNull(json);
          }
      }
      
      

      Run the test with attached file you will see the exception:

      java.lang.IllegalArgumentException: Invalid DMR unicode sequence. Expecting 4 hexadecimal digits but got '"p04'	at org.jboss.dmr.stream.JsonGrammarAnalyzer.newModelException(JsonGrammarAnalyzer.java:367)
      	at org.jboss.dmr.stream.JsonReaderImpl.newModelException(JsonReaderImpl.java:702)
      	at org.jboss.dmr.stream.JsonReaderImpl.readString(JsonReaderImpl.java:600)
      	at org.jboss.dmr.stream.JsonReaderImpl.next(JsonReaderImpl.java:306)
      	at org.jboss.dmr.ModelNodeFactory.readObjectFrom(ModelNodeFactory.java:216)
      	at org.jboss.dmr.ModelNodeFactory.readListFrom(ModelNodeFactory.java:194)
      	at org.jboss.dmr.ModelNodeFactory.readFrom(ModelNodeFactory.java:112)
      	at org.jboss.dmr.ModelNodeFactory.readFrom(ModelNodeFactory.java:67)
      	at org.jboss.dmr.ModelNodeFactory.readFrom(ModelNodeFactory.java:72)
      	at org.jboss.dmr.ModelNode.fromJSONString(ModelNode.java:1755)
      	at org.jboss.dmr.JsonFeaturesTest.testLongString(JsonFeaturesTest.java:65)
      	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      	at java.lang.reflect.Method.invoke(Method.java:498)
      	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
      	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
      	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
      	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
      	at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
      	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
      	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
      	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
      	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
      	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
      	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
      	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
      	at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
      	at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
      	at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
      	at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:33)
      	at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:230)
      	at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:58)
      
      

      If you remove the check the test passes.

       

        1. longstr.json
          5.19 MB
          Howard Gao

              jmesnil1@redhat.com Jeff Mesnil
              gaohoward Howard Gao
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Created:
                Updated: