Uploaded image for project: 'Log4j 2'
  1. Log4j 2
  2. LOG4J2-448

StringIndexOutOfBounds when using property substitution

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 2.0-beta9
    • Fix Version/s: 2.0-rc2
    • Component/s: API
    • Labels:
      None
    • Environment:

      All

      Description

      @org.apache.logging.log4j.core.lookup.StrSubstitutor# substitute(LogEvent , StringBuilder , int , int , List<String> ) @ Line 816-817 @new String(chars, offset, length). The String should be new String(chars, offset, length + lengthChange) this is because of the character deletion that might have happened for '$".

      See trace below:

      Exception in thread "main" java.lang.ExceptionInInitializerError
      Caused by: java.lang.StringIndexOutOfBoundsException: String index out of range: 63
      at java.lang.String.<init>(String.java:201)
      at org.apache.logging.log4j.core.lookup.StrSubstitutor.substitute(StrSubstitutor.java:848)
      at org.apache.logging.log4j.core.lookup.StrSubstitutor.substitute(StrSubstitutor.java:761)
      at org.apache.logging.log4j.core.lookup.StrSubstitutor.substitute(StrSubstitutor.java:737)
      at org.apache.logging.log4j.core.lookup.StrSubstitutor.replace(StrSubstitutor.java:306)
      at org.apache.logging.log4j.core.config.BaseConfiguration.createPluginObject(BaseConfiguration.java:720)
      at org.apache.logging.log4j.core.config.BaseConfiguration.createConfiguration(BaseConfiguration.java:595)
      at org.apache.logging.log4j.core.config.BaseConfiguration.createConfiguration(BaseConfiguration.java:587)
      at org.apache.logging.log4j.core.config.BaseConfiguration.doConfigure(BaseConfiguration.java:244)
      at org.apache.logging.log4j.core.config.BaseConfiguration.start(BaseConfiguration.java:142)
      at org.apache.logging.log4j.core.LoggerContext.setConfiguration(LoggerContext.java:339)
      at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:378)
      at org.apache.logging.log4j.core.LoggerContext.start(LoggerContext.java:149)
      at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:85)
      at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:34)
      at org.apache.logging.log4j.LogManager.getContext(LogManager.java:200)
      at org.slf4j.helpers.Log4jLoggerFactory$PrivateManager.getContext(Log4jLoggerFactory.java:104)
      at org.slf4j.helpers.Log4jLoggerFactory.getContext(Log4jLoggerFactory.java:90)
      at org.slf4j.helpers.Log4jLoggerFactory.getLogger(Log4jLoggerFactory.java:46)
      at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:270)
      at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:281)

        Issue Links

          Activity

          Hide
          garydgregory Gary Gregory added a comment -

          Can you provide a specific example? Better yet, a unit test?

          Thank you,
          Gary

          Show
          garydgregory Gary Gregory added a comment - Can you provide a specific example? Better yet, a unit test? Thank you, Gary
          Hide
          remkop@yahoo.com Remko Popma added a comment -

          What was the property string that failed?
          Can you give some more detail so we can reproduce the issue?

          Show
          remkop@yahoo.com Remko Popma added a comment - What was the property string that failed? Can you give some more detail so we can reproduce the issue?
          Hide
          remkop@yahoo.com Remko Popma added a comment -

          X86core, I agree with your analysis that the chars array may be modified, in which case the length should be adjusted by lengthChange like you pointed out.

          However, this code is used a lot and I hesitate to make changes without reproducing the issue first...
          Could you provide the configuration file you used when the error above occurred, or another test case?

          Show
          remkop@yahoo.com Remko Popma added a comment - X86core, I agree with your analysis that the chars array may be modified, in which case the length should be adjusted by lengthChange like you pointed out. However, this code is used a lot and I hesitate to make changes without reproducing the issue first... Could you provide the configuration file you used when the error above occurred, or another test case?
          Hide
          gdespres Després Gwénaël added a comment - - edited

          Hi, I have the same issue with my test. It's easily reproducible with the conf :

          log4j2.xml
          <?xml version="1.0" encoding="UTF-8"?>
          <configuration status="warn">
              <properties>
                  <property name="filters">org.junit,org.apache.maven,org.eclipse,sun.reflect,java.lang.reflect</property>
              </properties>
              <appenders>
                  <console name="console" target="SYSTEM_OUT">
                      <patternLayout pattern="%d{HH:mm:ss,SSS} [%t] %-5level [$${date:yyyyMMdd.HHmmSS}] %logger{1}.%method:%line - %msg%n%rEx{filters(${filters})}" />
                  </console>
              </appenders>
              <loggers>
                  <root level="warn">
                      <appenderRef ref="console" />
                  </root>
              </loggers>
          </configuration>
          

          In the example I use

           $${date:xxx} 

          but in real, I use a personal lookup.

          Show
          gdespres Després Gwénaël added a comment - - edited Hi, I have the same issue with my test. It's easily reproducible with the conf : log4j2.xml <?xml version= "1.0" encoding= "UTF-8" ?> <configuration status= "warn" > <properties> <property name= "filters" >org.junit,org.apache.maven,org.eclipse,sun.reflect,java.lang.reflect</property> </properties> <appenders> <console name= "console" target= "SYSTEM_OUT" > <patternLayout pattern= "%d{HH:mm:ss,SSS} [%t] %-5level [$${date:yyyyMMdd.HHmmSS}] %logger{1}.%method:%line - %msg%n%rEx{filters(${filters})}" /> </console> </appenders> <loggers> <root level= "warn" > <appenderRef ref= "console" /> </root> </loggers> </configuration> In the example I use $${date:xxx} but in real, I use a personal lookup.
          Hide
          ralph.goers@dslextreme.com Ralph Goers added a comment -

          Fixed in revision 1589024. Please verify and close.

          Show
          ralph.goers@dslextreme.com Ralph Goers added a comment - Fixed in revision 1589024. Please verify and close.

            People

            • Assignee:
              Unassigned
              Reporter:
              X86core X86core
            • Votes:
              2 Vote for this issue
              Watchers:
              7 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development