Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-71926

Pipeline serialization issue when String arguments contains NUL character '\0'

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Minor Minor
    • workflow-cps-plugin
    • None
    • core:2.421
      workflow-api:1267.vd9b_a_ddd9eb_47
      workflow-cps:3773.v505e0052522c
      workflow-durable-task:1289.v4d3e7b_01546b_
      workflow-support:848.v5a_383b_d14921

      When a String variable contains NUL char - i.e. \0 or unicode \u0000 - and is used as arguments of a step, the flow node serialization fails with:

      2023-08-30 02:29:36.827+0000 [id=293]	WARNING	o.j.p.w.cps.CpsThreadGroup#saveProgramIfPossible: Error persisting FlowNode storage before saving program
      com.thoughtworks.xstream.io.StreamException: Invalid character 0x0 in XML stream
      	at hudson.util.PrettyPrintWriter.lambda$writeText$0(PrettyPrintWriter.java:220)
      	at java.base/java.lang.StringLatin1$CharsSpliterator.forEachRemaining(StringLatin1.java:770)
      	at java.base/java.util.stream.IntPipeline$Head.forEach(IntPipeline.java:593)
      	at hudson.util.PrettyPrintWriter.writeText(PrettyPrintWriter.java:214)
      	at hudson.util.PrettyPrintWriter.writeText(PrettyPrintWriter.java:210)
      	at hudson.util.PrettyPrintWriter.setValue(PrettyPrintWriter.java:192)
      	at com.thoughtworks.xstream.io.WriterWrapper.setValue(WriterWrapper.java:45)
      	at com.thoughtworks.xstream.converters.SingleValueConverterWrapper.marshal(SingleValueConverterWrapper.java:45)
      	at com.thoughtworks.xstream.core.AbstractReferenceMarshaller.convert(AbstractReferenceMarshaller.java:50)
      	at com.thoughtworks.xstream.core.TreeMarshaller.convertAnother(TreeMarshaller.java:59)
      	at com.thoughtworks.xstream.core.TreeMarshaller.convertAnother(TreeMarshaller.java:44)
      	at com.thoughtworks.xstream.core.AbstractReferenceMarshaller$1.convertAnother(AbstractReferenceMarshaller.java:87)
      	at com.thoughtworks.xstream.converters.collections.AbstractCollectionConverter.writeBareItem(AbstractCollectionConverter.java:94)
      	at com.thoughtworks.xstream.converters.collections.AbstractCollectionConverter.writeItem(AbstractCollectionConverter.java:66)
      	at com.thoughtworks.xstream.converters.collections.AbstractCollectionConverter.writeCompleteItem(AbstractCollectionConverter.java:81)
      	at com.thoughtworks.xstream.converters.collections.MapConverter.marshal(MapConverter.java:80)
      	at com.thoughtworks.xstream.core.AbstractReferenceMarshaller.convert(AbstractReferenceMarshaller.java:68)
      	at com.thoughtworks.xstream.core.TreeMarshaller.convertAnother(TreeMarshaller.java:59)
      	at com.thoughtworks.xstream.core.AbstractReferenceMarshaller$1.convertAnother(AbstractReferenceMarshaller.java:83)
      	at hudson.util.RobustReflectionConverter.marshallField(RobustReflectionConverter.java:283)
      	at hudson.util.RobustReflectionConverter$2.writeField(RobustReflectionConverter.java:270)
      Caused: java.lang.RuntimeException: Failed to serialize org.jenkinsci.plugins.workflow.cps.actions.ArgumentsActionImpl#arguments for class org.jenkinsci.plugins.workflow.cps.actions.ArgumentsActionImpl
      	at hudson.util.RobustReflectionConverter$2.writeField(RobustReflectionConverter.java:274)
      	at hudson.util.RobustReflectionConverter$2.visit(RobustReflectionConverter.java:241)
      	at com.thoughtworks.xstream.converters.reflection.PureJavaReflectionProvider.visitSerializableFields(PureJavaReflectionProvider.java:174)
      	at hudson.util.RobustReflectionConverter.doMarshal(RobustReflectionConverter.java:226)
      	at hudson.util.RobustReflectionConverter.marshal(RobustReflectionConverter.java:163)
      	at com.thoughtworks.xstream.core.AbstractReferenceMarshaller.convert(AbstractReferenceMarshaller.java:68)
      	at com.thoughtworks.xstream.core.TreeMarshaller.convertAnother(TreeMarshaller.java:59)
      	at com.thoughtworks.xstream.core.TreeMarshaller.convertAnother(TreeMarshaller.java:44)
      	at com.thoughtworks.xstream.core.AbstractReferenceMarshaller$1.convertAnother(AbstractReferenceMarshaller.java:87)
      	at com.thoughtworks.xstream.converters.collections.AbstractCollectionConverter.writeBareItem(AbstractCollectionConverter.java:94)
      	at com.thoughtworks.xstream.converters.collections.AbstractCollectionConverter.writeItem(AbstractCollectionConverter.java:66)
      	at com.thoughtworks.xstream.converters.collections.AbstractCollectionConverter.writeCompleteItem(AbstractCollectionConverter.java:81)
      	at com.thoughtworks.xstream.converters.collections.ArrayConverter.marshal(ArrayConverter.java:45)
      	at com.thoughtworks.xstream.core.AbstractReferenceMarshaller.convert(AbstractReferenceMarshaller.java:68)
      	at com.thoughtworks.xstream.core.TreeMarshaller.convertAnother(TreeMarshaller.java:59)
      	at com.thoughtworks.xstream.core.AbstractReferenceMarshaller$1.convertAnother(AbstractReferenceMarshaller.java:83)
      	at hudson.util.RobustReflectionConverter.marshallField(RobustReflectionConverter.java:283)
      	at hudson.util.RobustReflectionConverter$2.writeField(RobustReflectionConverter.java:270)
      Caused: java.lang.RuntimeException: Failed to serialize org.jenkinsci.plugins.workflow.support.storage.SimpleXStreamFlowNodeStorage$Tag#actions for class org.jenkinsci.plugins.workflow.support.storage.SimpleXStreamFlowNodeStorage$Tag
      	at hudson.util.RobustReflectionConverter$2.writeField(RobustReflectionConverter.java:274)
      	at hudson.util.RobustReflectionConverter$2.visit(RobustReflectionConverter.java:241)
      	at com.thoughtworks.xstream.converters.reflection.PureJavaReflectionProvider.visitSerializableFields(PureJavaReflectionProvider.java:174)
      	at hudson.util.RobustReflectionConverter.doMarshal(RobustReflectionConverter.java:226)
      	at hudson.util.RobustReflectionConverter.marshal(RobustReflectionConverter.java:163)
      	at com.thoughtworks.xstream.core.AbstractReferenceMarshaller.convert(AbstractReferenceMarshaller.java:68)
      	at com.thoughtworks.xstream.core.TreeMarshaller.convertAnother(TreeMarshaller.java:59)
      	at com.thoughtworks.xstream.core.TreeMarshaller.convertAnother(TreeMarshaller.java:44)
      	at com.thoughtworks.xstream.core.TreeMarshaller.start(TreeMarshaller.java:83)
      	at com.thoughtworks.xstream.core.AbstractTreeMarshallingStrategy.marshal(AbstractTreeMarshallingStrategy.java:37)
      	at com.thoughtworks.xstream.XStream.marshal(XStream.java:1303)
      	at com.thoughtworks.xstream.XStream.marshal(XStream.java:1292)
      	at com.thoughtworks.xstream.XStream.toXML(XStream.java:1265)
      	at hudson.XmlFile.write(XmlFile.java:213)
      Caused: java.io.IOException
      	at hudson.XmlFile.write(XmlFile.java:220)
      	at org.jenkinsci.plugins.workflow.support.PipelineIOUtils.writeByXStream(PipelineIOUtils.java:30)
      	at org.jenkinsci.plugins.workflow.support.storage.SimpleXStreamFlowNodeStorage.writeNode(SimpleXStreamFlowNodeStorage.java:179)
      	at org.jenkinsci.plugins.workflow.support.storage.SimpleXStreamFlowNodeStorage.flush(SimpleXStreamFlowNodeStorage.java:160)
      	at org.jenkinsci.plugins.workflow.cps.CpsFlowExecution$TimingFlowNodeStorage.flush(CpsFlowExecution.java:1934)
      	at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.saveProgramIfPossible(CpsThreadGroup.java:532)
      	at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.run(CpsThreadGroup.java:463)
      	at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:330)
      	at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:294)
      	at org.jenkinsci.plugins.workflow.cps.CpsVmExecutorService$2.call(CpsVmExecutorService.java:67)
      	at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
      	at hudson.remoting.SingleLaneExecutorService$1.run(SingleLaneExecutorService.java:139)
      	at jenkins.util.ContextResettingExecutorService$1.run(ContextResettingExecutorService.java:28)
      	at jenkins.security.ImpersonatingExecutorService$1.run(ImpersonatingExecutorService.java:68)
      	at jenkins.util.ErrorLoggingExecutorService.lambda$wrap$0(ErrorLoggingExecutorService.java:51)
      	at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
      	at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
      	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
      	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
      	at java.base/java.lang.Thread.run(Thread.java:829)
      

      The pipeline however succeeds..

      How to Reproduce:

      node {
          // This prints fine
          sh(script: "printf \"test\\0test\"", returnStdout: true)
          def nullCharTest = sh(script: "printf \"test\\0test\"", returnStdout: true)
          // This fails serialization
          echo(nullCharTest)
      }
      

      Execute the pipeline and look at the Jenkins logs.

            jglick Jesse Glick
            allan_burdajewicz Allan BURDAJEWICZ
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: