Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BitSet deserialization does not work #590

Closed
pjfanning opened this issue Aug 5, 2022 · 0 comments
Closed

BitSet deserialization does not work #590

pjfanning opened this issue Aug 5, 2022 · 0 comments
Assignees
Labels

Comments

@pjfanning
Copy link
Member

pjfanning commented Aug 5, 2022

Spotted in jsoniter-scala benchmark tests.

Scala BitSets are sized based on the largest int stored in them (similar to Java implementation). This means that if you accept input files from untrusted parties that malicious users can craft an input file that leads to the parser using a lot more memory than you would expect.

BitSet serialization already works in jackson-module-scala (jn
jackson-module-scala 2.13.3, for instance). An array with sorted ints is output (Scala BitSets implement SortedSet[Int].

BitSet deserialization does not work in jackson-module-scala up to v2.14.0.

Exceptions look like:

[info]   java.lang.IllegalArgumentException: Unsupported value type: java.lang.Object
[info]   at com.fasterxml.jackson.module.scala.introspect.OrderingLocator$.$anonfun$locate$3(OrderingLocator.scala:37)
[info]   at scala.Option.getOrElse(Option.scala:201)
[info]   at com.fasterxml.jackson.module.scala.introspect.OrderingLocator$.locate(OrderingLocator.scala:26)
[info]   at com.fasterxml.jackson.module.scala.deser.SortedSetDeserializerModule$$anon$1.builderFor(SortedSetDeserializerModule.scala:27)
[info]   at com.fasterxml.jackson.module.scala.deser.SortedSetDeserializerModule$$anon$1.builderFor(SortedSetDeserializerModule.scala:12)
[info]   at com.fasterxml.jackson.module.scala.deser.GenericFactoryDeserializerResolver.$anonfun$builderFor$3(GenericFactoryDeserializerResolver.scala:28)

In jackson-module-scala v2.14.0 and above, you can addModule(BitSetDeserializerModule). Use of this additional module is discouraged but if you know the risks and are sure the inputs documents you will parse are safe, then you can enable this.

jackson-module-scala v2.14.0 also chnages the exception you should get if you don't register the new module but attempt to deserialize a Scala BitSet. This will now lead to an InvalidDefinitionException.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant