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

Very long content token string parameter triggers a StackOverflowError

    Details

    • Similar Issues:

      Description

      A string parameter more than a couple of hundred characters in length triggers a StackOverflowError when it gets parsed by ContentBuilder.

      Here's a partial stack trace for a BUILD_LOG_MULTILINE_REGEX content token with a long regex="..." parameter (-XX:MaxJavaStackTraceDepth=16384 JVM option required to see the bottom of the stack trace, because the number of stack frames is larger than the default printed depth):

      ...
      at java.util.regex.Matcher.search(Matcher.java:1105)
      at java.util.regex.Matcher.find(Matcher.java:535)
      at hudson.plugins.emailext.plugins.ContentBuilder$Tokenizer.find(ContentBuilder.java:184)
      at hudson.plugins.emailext.plugins.ContentBuilder.replaceTokensWithContent(ContentBuilder.java:106)
      at hudson.plugins.emailext.plugins.ContentBuilder.transformText(ContentBuilder.java:88)
      at hudson.plugins.emailext.ExtendedEmailPublisher.getContent(ExtendedEmailPublisher.java:536)
      at hudson.plugins.emailext.ExtendedEmailPublisher.createMail(ExtendedEmailPublisher.java:363)
      at hudson.plugins.emailext.ExtendedEmailPublisher.sendMail(ExtendedEmailPublisher.java:273)
      at hudson.plugins.emailext.ExtendedEmailPublisher._perform(ExtendedEmailPublisher.java:265)
      at hudson.plugins.emailext.ExtendedEmailPublisher.perform(ExtendedEmailPublisher.java:225)
      at hudson.tasks.BuildStepMonitor$3.perform(BuildStepMonitor.java:36)
      

        Attachments

          Activity

          sarowe Steve Rowe created issue -
          Hide
          slide_o_mix Alex Earl added a comment -

          Please supply your build configuration.

          Show
          slide_o_mix Alex Earl added a comment - Please supply your build configuration.
          Hide
          sarowe Steve Rowe added a comment -

          Here's the culprit: line #142 in ContentBuilder.java:

          // Sequence of (1) not \ " CR LF and (2) \ followed by (CR)LF, or not CR LF
          private static final String stringRegex = "\"([^\\\\\"\\r\\n]|(\\\\(?:\r?\n|.)))*\"";
          

          This can be fixed by adding a possessive quantifier to the above regex. I'll make a pull request shortly that adds a test and a fix. (The test fails without the fix, and succeeds with it.)

          Show
          sarowe Steve Rowe added a comment - Here's the culprit: line #142 in ContentBuilder.java : // Sequence of (1) not \ " CR LF and (2) \ followed by (CR)LF, or not CR LF private static final String stringRegex = "\"([^\\\\\"\\r\\n]|(\\\\(?:\r?\n|.)))*\""; This can be fixed by adding a possessive quantifier to the above regex. I'll make a pull request shortly that adds a test and a fix. (The test fails without the fix, and succeeds with it.)
          Hide
          sarowe Steve Rowe added a comment -
          Show
          sarowe Steve Rowe added a comment - Pull request: https://github.com/jenkinsci/email-ext-plugin/pull/41
          Hide
          sarowe Steve Rowe added a comment -

          Configuration that triggers the bug:

          Build: ${BUILD_URL}
          
          ${FAILED_TESTS}
          
          Build Log:
          ${BUILD_LOG_MULTILINE_REGEX,regex="(?x:                                                                              \
          \
          # Compilation failures (possessive quantifier on '*+' prevents backtracking and reduces stack usage)                 \
          (?:.*\\[javac\\]\\s++(?![1-9]\\d*\\s+error).*\\r?\\n)*+.*\\[javac\\]\\s+[1-9]\\d*\\s+error.*\\r?\\n                  \
          \
          # Test failures (possessive quantifier on '*+' prevents backtracking and reduces stack usage)                        \
          |.*\\[junit4\\]\\s+Suite:.*+\\s++.*\\[junit4\\]\\s++(?!Completed)(?!IGNOR).*\\r?\\n                                  \
              (?:.*\\[junit4\\]\\s++(?!Completed\\s+on.*<<<\\s*FAILURES!).*\\r?\\n)*+                                          \
              .*\\[junit4\\]\\s++Completed\\s+on.*<<<\\s*FAILURES!\\r?\\n                                                      \
          \
          # Source file license problems (possessive quantifier on '*+' prevents backtracking and reduces stack usage)         \
          |.*rat-sources:.*\\r?\\n(?:.*\\[echo\\]\\s++(?![1-9]\\d*\\s+Unknown\\s+Licenses).*\\r?\\n)*+                         \
                         .*\\[echo\\]\\s+[1-9]\\d*\\s+Unknown\\s+Licenses.*\\r?\\n(?:.*\\[echo\\].*\\r?\\n)*+                  \
          \
          # Third-party dependency license problems - include 2 preceding lines and 1 following line                           \
          |(?:.*\\r?\\n){2}.*\\[licenses\\]\\s+MISSING\\s+sha1(?:.*\\r?\\n){2}                                                 \
          \
          # Javadoc warnings (possessive quantifier on '*+' prevents backtracking and reduces stack usage)                     \
          |(?:.*\\[javadoc\\]\\s++(?![1-9]\\d*\\s+warnings).*\\r?\\n)*+.*\\[javadoc\\]\\s*[1-9]\\d*\\s+warnings.*\\r?\\n       \
          \
          # Other javadocs problems: broken links and missing javadocs                                                         \
          |.*javadocs-lint:.*\\r?\\n(?:.*\\[echo\\].*\\r?\n)*+                                                                 \
          \
          # Thread dumps - include 1 preceding line and the remainder of the log                                               \
          |.*\\r?\\n.*Full\\s+thread\\s+dump(?s:.*+)                                                                           \
          \
          # Jenkins problems - include the remainder of the log                                                                \
          |.*(?:FATAL|ERROR):(?s:.*+)                                                                                          \
          \
          # The Ant call stack - include the remainder of the log                                                              \
          |.*BUILD\\s+FAILED(?s:.*+)                                                                                           \
          )"}
          
          Show
          sarowe Steve Rowe added a comment - Configuration that triggers the bug: Build: ${BUILD_URL} ${FAILED_TESTS} Build Log: ${BUILD_LOG_MULTILINE_REGEX,regex="(?x: \ \ # Compilation failures (possessive quantifier on '*+' prevents backtracking and reduces stack usage) \ (?:.*\\[javac\\]\\s++(?![1-9]\\d*\\s+error).*\\r?\\n)*+.*\\[javac\\]\\s+[1-9]\\d*\\s+error.*\\r?\\n \ \ # Test failures (possessive quantifier on '*+' prevents backtracking and reduces stack usage) \ |.*\\[junit4\\]\\s+Suite:.*+\\s++.*\\[junit4\\]\\s++(?!Completed)(?!IGNOR).*\\r?\\n \ (?:.*\\[junit4\\]\\s++(?!Completed\\s+on.*<<<\\s*FAILURES!).*\\r?\\n)*+ \ .*\\[junit4\\]\\s++Completed\\s+on.*<<<\\s*FAILURES!\\r?\\n \ \ # Source file license problems (possessive quantifier on '*+' prevents backtracking and reduces stack usage) \ |.*rat-sources:.*\\r?\\n(?:.*\\[echo\\]\\s++(?![1-9]\\d*\\s+Unknown\\s+Licenses).*\\r?\\n)*+ \ .*\\[echo\\]\\s+[1-9]\\d*\\s+Unknown\\s+Licenses.*\\r?\\n(?:.*\\[echo\\].*\\r?\\n)*+ \ \ # Third-party dependency license problems - include 2 preceding lines and 1 following line \ |(?:.*\\r?\\n){2}.*\\[licenses\\]\\s+MISSING\\s+sha1(?:.*\\r?\\n){2} \ \ # Javadoc warnings (possessive quantifier on '*+' prevents backtracking and reduces stack usage) \ |(?:.*\\[javadoc\\]\\s++(?![1-9]\\d*\\s+warnings).*\\r?\\n)*+.*\\[javadoc\\]\\s*[1-9]\\d*\\s+warnings.*\\r?\\n \ \ # Other javadocs problems: broken links and missing javadocs \ |.*javadocs-lint:.*\\r?\\n(?:.*\\[echo\\].*\\r?\n)*+ \ \ # Thread dumps - include 1 preceding line and the remainder of the log \ |.*\\r?\\n.*Full\\s+thread\\s+dump(?s:.*+) \ \ # Jenkins problems - include the remainder of the log \ |.*(?:FATAL|ERROR):(?s:.*+) \ \ # The Ant call stack - include the remainder of the log \ |.*BUILD\\s+FAILED(?s:.*+) \ )"}
          Hide
          scm_issue_link SCM/JIRA link daemon added a comment -

          Code changed in jenkins
          User: Steve Rowe
          Path:
          src/main/java/hudson/plugins/emailext/plugins/ContentBuilder.java
          src/test/java/hudson/plugins/emailext/plugins/ContentBuilderTest.java
          http://jenkins-ci.org/commit/email-ext-plugin/14f50f8ce8f089c170002a345d5612e23ab24fae
          Log:
          JENKINS-14132: Very long content token string parameter triggers a StackOverflowError

          Show
          scm_issue_link SCM/JIRA link daemon added a comment - Code changed in jenkins User: Steve Rowe Path: src/main/java/hudson/plugins/emailext/plugins/ContentBuilder.java src/test/java/hudson/plugins/emailext/plugins/ContentBuilderTest.java http://jenkins-ci.org/commit/email-ext-plugin/14f50f8ce8f089c170002a345d5612e23ab24fae Log: JENKINS-14132 : Very long content token string parameter triggers a StackOverflowError
          Hide
          scm_issue_link SCM/JIRA link daemon added a comment -

          Code changed in jenkins
          User: slide
          Path:
          src/main/java/hudson/plugins/emailext/plugins/ContentBuilder.java
          src/test/java/hudson/plugins/emailext/plugins/ContentBuilderTest.java
          http://jenkins-ci.org/commit/email-ext-plugin/b0c21b81ddc3ed860e153a21f527eed508e7e1b8
          Log:
          Merge pull request #41 from sarowe/master

          Fix for JENKINS-14132: Very long content token string parameter triggers a StackOverflowError

          Compare: https://github.com/jenkinsci/email-ext-plugin/compare/cd04b173541f...b0c21b81ddc3

          Show
          scm_issue_link SCM/JIRA link daemon added a comment - Code changed in jenkins User: slide Path: src/main/java/hudson/plugins/emailext/plugins/ContentBuilder.java src/test/java/hudson/plugins/emailext/plugins/ContentBuilderTest.java http://jenkins-ci.org/commit/email-ext-plugin/b0c21b81ddc3ed860e153a21f527eed508e7e1b8 Log: Merge pull request #41 from sarowe/master Fix for JENKINS-14132 : Very long content token string parameter triggers a StackOverflowError Compare: https://github.com/jenkinsci/email-ext-plugin/compare/cd04b173541f...b0c21b81ddc3
          Hide
          slide_o_mix Alex Earl added a comment -

          This will be released in 2.23 (roughly July 1, 2012)

          Show
          slide_o_mix Alex Earl added a comment - This will be released in 2.23 (roughly July 1, 2012)
          slide_o_mix Alex Earl made changes -
          Field Original Value New Value
          Status Open [ 1 ] Resolved [ 5 ]
          Resolution Fixed [ 1 ]
          Hide
          sarowe Steve Rowe added a comment -

          Thanks!

          Show
          sarowe Steve Rowe added a comment - Thanks!
          Hide
          scm_issue_link SCM/JIRA link daemon added a comment -

          Code changed in jenkins
          User: Steve Rowe
          Path:
          src/main/java/org/jenkinsci/plugins/tokenmacro/Tokenizer.java
          src/test/java/org/jenkinsci/plugins/tokenmacro/TokenMacroTest.java
          http://jenkins-ci.org/commit/token-macro-plugin/deb32004e570d7f106233444ecc3eedd752f9c97
          Log:
          Allow backslash-escaped terminators in content token string arguments; JENKINS-14132: Very long content string parameter triggers a StackOverflowError

          Show
          scm_issue_link SCM/JIRA link daemon added a comment - Code changed in jenkins User: Steve Rowe Path: src/main/java/org/jenkinsci/plugins/tokenmacro/Tokenizer.java src/test/java/org/jenkinsci/plugins/tokenmacro/TokenMacroTest.java http://jenkins-ci.org/commit/token-macro-plugin/deb32004e570d7f106233444ecc3eedd752f9c97 Log: Allow backslash-escaped terminators in content token string arguments; JENKINS-14132 : Very long content string parameter triggers a StackOverflowError
          Hide
          scm_issue_link SCM/JIRA link daemon added a comment -

          Code changed in jenkins
          User: Alex Earl
          Path:
          src/main/java/org/jenkinsci/plugins/tokenmacro/Tokenizer.java
          src/test/java/org/jenkinsci/plugins/tokenmacro/TokenMacroTest.java
          http://jenkins-ci.org/commit/token-macro-plugin/806525fc9cdfce38d42db95194747d91e82d68e0
          Log:
          Merge pull request #10 from sarowe/master

          Address regressions in Email-ext v2.29 due to new dependency on token-macro-plugin: backslash-escaped terminators in content token string arguments no longer work; and very long content string parameters trigger StackOverflowErrors (JENKINS-14132)

          Compare: https://github.com/jenkinsci/token-macro-plugin/compare/bdc4345d1bcc...806525fc9cdf

          Show
          scm_issue_link SCM/JIRA link daemon added a comment - Code changed in jenkins User: Alex Earl Path: src/main/java/org/jenkinsci/plugins/tokenmacro/Tokenizer.java src/test/java/org/jenkinsci/plugins/tokenmacro/TokenMacroTest.java http://jenkins-ci.org/commit/token-macro-plugin/806525fc9cdfce38d42db95194747d91e82d68e0 Log: Merge pull request #10 from sarowe/master Address regressions in Email-ext v2.29 due to new dependency on token-macro-plugin: backslash-escaped terminators in content token string arguments no longer work; and very long content string parameters trigger StackOverflowErrors ( JENKINS-14132 ) Compare: https://github.com/jenkinsci/token-macro-plugin/compare/bdc4345d1bcc...806525fc9cdf
          rtyler R. Tyler Croy made changes -
          Workflow JNJira [ 144763 ] JNJira + In-Review [ 191171 ]

            People

            • Assignee:
              slide_o_mix Alex Earl
              Reporter:
              sarowe Steve Rowe
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: