Skip to content

com.typesafe.config.impl.BadMap throws exception if hashCode returns Integer.MIN_VALUE #1886

@dudaerich

Description

@dudaerich

Although the bug is present in https://github.com/lightbend/config/ I am reporting it here as the library is not maintained - see this discussion as evidence.

The problem is in the following code:

int hash = Math.abs(k.hashCode());
int i = hash % entries.length;
Entry e = entries[i];

The Javadoc for Math.abs says: "Note that if the argument is equal to the value of Integer.MIN_VALUE, the most negative representable int value, the result is that same value, which is negative.". So, if the k.hashCode() returns Integer.MIN_VALUE, the variable i is negative and the code tries to access element of array with negative index resulting into index out of bounds.

In my case, the variable k refers to com.typesafe.config.impl.MemoKey which is not under my control, so I cannot influence the hashCode method. See attached stack trace.

This error appears intermittently in our tests but we saw it also on production.

Caused by : 
Index -59 out of bounds for length 61
com.typesafe.config.impl.BadMap.get(BadMap.java:105)
com.typesafe.config.impl.ResolveMemos.get(ResolveMemos.java:22)
com.typesafe.config.impl.ResolveContext.realResolve(ResolveContext.java:163)
com.typesafe.config.impl.ResolveContext.resolve(ResolveContext.java:146)
com.typesafe.config.impl.ResolveSource.findInObject(ResolveSource.java:47)
com.typesafe.config.impl.ResolveSource.lookupSubst(ResolveSource.java:97)
com.typesafe.config.impl.ConfigReference.resolveSubstitutions(ConfigReference.java:74)
com.typesafe.config.impl.ResolveContext.realResolve(ResolveContext.java:183)
com.typesafe.config.impl.ResolveContext.resolve(ResolveContext.java:146)
com.typesafe.config.impl.ConfigConcatenation.resolveSubstitutions(ConfigConcatenation.java:205)
com.typesafe.config.impl.ResolveContext.realResolve(ResolveContext.java:183)
com.typesafe.config.impl.ResolveContext.resolve(ResolveContext.java:146)
com.typesafe.config.impl.SimpleConfigObject$ResolveModifier.modifyChildMayThrow(SimpleConfigObject.java:380)
com.typesafe.config.impl.SimpleConfigObject.modifyMayThrow(SimpleConfigObject.java:313)
com.typesafe.config.impl.SimpleConfigObject.resolveSubstitutions(SimpleConfigObject.java:399)
com.typesafe.config.impl.ResolveContext.realResolve(ResolveContext.java:183)
com.typesafe.config.impl.ResolveContext.resolve(ResolveContext.java:146)
com.typesafe.config.impl.SimpleConfigObject$ResolveModifier.modifyChildMayThrow(SimpleConfigObject.java:380)
com.typesafe.config.impl.SimpleConfigObject.modifyMayThrow(SimpleConfigObject.java:313)
com.typesafe.config.impl.SimpleConfigObject.resolveSubstitutions(SimpleConfigObject.java:399)
com.typesafe.config.impl.ResolveContext.realResolve(ResolveContext.java:183)
com.typesafe.config.impl.ResolveContext.resolve(ResolveContext.java:146)
com.typesafe.config.impl.SimpleConfigObject$ResolveModifier.modifyChildMayThrow(SimpleConfigObject.java:380)
com.typesafe.config.impl.SimpleConfigObject.modifyMayThrow(SimpleConfigObject.java:313)
com.typesafe.config.impl.SimpleConfigObject.resolveSubstitutions(SimpleConfigObject.java:399)
com.typesafe.config.impl.ResolveContext.realResolve(ResolveContext.java:183)
com.typesafe.config.impl.ResolveContext.resolve(ResolveContext.java:146)
com.typesafe.config.impl.SimpleConfigObject$ResolveModifier.modifyChildMayThrow(SimpleConfigObject.java:380)
com.typesafe.config.impl.SimpleConfigObject.modifyMayThrow(SimpleConfigObject.java:313)
com.typesafe.config.impl.SimpleConfigObject.resolveSubstitutions(SimpleConfigObject.java:399)
com.typesafe.config.impl.ResolveContext.realResolve(ResolveContext.java:183)
com.typesafe.config.impl.ResolveContext.resolve(ResolveContext.java:146)
com.typesafe.config.impl.SimpleConfigObject$ResolveModifier.modifyChildMayThrow(SimpleConfigObject.java:380)
com.typesafe.config.impl.SimpleConfigObject.modifyMayThrow(SimpleConfigObject.java:313)
com.typesafe.config.impl.SimpleConfigObject.resolveSubstitutions(SimpleConfigObject.java:399)
com.typesafe.config.impl.ResolveContext.realResolve(ResolveContext.java:183)
com.typesafe.config.impl.ResolveContext.resolve(ResolveContext.java:146)
com.typesafe.config.impl.SimpleConfigObject$ResolveModifier.modifyChildMayThrow(SimpleConfigObject.java:380)
com.typesafe.config.impl.SimpleConfigObject.modifyMayThrow(SimpleConfigObject.java:313)
com.typesafe.config.impl.SimpleConfigObject.resolveSubstitutions(SimpleConfigObject.java:399)
com.typesafe.config.impl.ResolveContext.realResolve(ResolveContext.java:183)
com.typesafe.config.impl.ResolveContext.resolve(ResolveContext.java:146)
com.typesafe.config.impl.ResolveContext.resolve(ResolveContext.java:235)
com.typesafe.config.impl.SimpleConfig.resolveWith(SimpleConfig.java:79)
com.typesafe.config.impl.SimpleConfig.resolve(SimpleConfig.java:69)
com.typesafe.config.impl.SimpleConfig.resolve(SimpleConfig.java:42)
com.typesafe.config.ConfigFactory.load(ConfigFactory.java:219)
com.typesafe.config.ConfigFactory.load(ConfigFactory.java:186)
com.typesafe.config.ConfigFactory$1.call(ConfigFactory.java:264)
com.typesafe.config.ConfigFactory$1.call(ConfigFactory.java:261)
com.typesafe.config.impl.ConfigImpl$LoaderCache.getOrElseUpdate(ConfigImpl.java:66)
com.typesafe.config.impl.ConfigImpl.computeCachedConfig(ConfigImpl.java:93)
com.typesafe.config.ConfigFactory.load(ConfigFactory.java:261)
org.apache.pekko.actor.ActorSystem$.$anonfun$apply$4(ActorSystem.scala:280)
scala.Option.getOrElse(Option.scala:201)
org.apache.pekko.actor.ActorSystem$.apply(ActorSystem.scala:280)
org.apache.pekko.actor.ActorSystem$.apply(ActorSystem.scala:327)
org.apache.pekko.actor.ActorSystem.apply(ActorSystem.scala:271)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions