Class DepthLimitedJsonReader

java.lang.Object
org.bson.AbstractBsonReader
org.bson.json.JsonReader
com.hypixel.hytale.server.core.util.DepthLimitedJsonReader
All Implemented Interfaces:
Closeable, AutoCloseable, org.bson.BsonReader

public final class DepthLimitedJsonReader extends org.bson.json.JsonReader
A JsonReader that aborts once JSON nests deeper than maxDepth levels.

org.bson decodes documents and arrays by recursing once per nesting level (BsonDocumentCodec.decode -> readValue -> decode); with no depth bound, deeply nested input overflows the JVM stack. Every real document/array boundary passes through the overridden readStart*/readEnd* methods, so incrementing on entry and throwing past the limit halts the codec's recursion with a controlled exception well before the stack is exhausted. The extended-JSON lookahead ($oid, $date, ...) is token-level and opens no document context, so it does not affect the count.

  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static final class 
    Thrown when the JSON input nests deeper than the reader's configured limit.

    Nested classes/interfaces inherited from class org.bson.AbstractBsonReader

    org.bson.AbstractBsonReader.State
  • Constructor Summary

    Constructors
    Constructor
    Description
    DepthLimitedJsonReader(String json, int maxDepth)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
     
    void
     
    void
     
    void
     

    Methods inherited from class org.bson.json.JsonReader

    doReadDecimal128, getMark, readBsonType

    Methods inherited from class org.bson.AbstractBsonReader

    close, getCurrentBsonType, getCurrentName, getState, peekBinarySize, peekBinarySubType, readBinaryData, readBinaryData, readBoolean, readBoolean, readDateTime, readDateTime, readDBPointer, readDBPointer, readDecimal128, readDecimal128, readDouble, readDouble, readInt32, readInt32, readInt64, readInt64, readJavaScript, readJavaScript, readJavaScriptWithScope, readJavaScriptWithScope, readMaxKey, readMaxKey, readMinKey, readMinKey, readName, readName, readNull, readNull, readObjectId, readObjectId, readRegularExpression, readRegularExpression, readString, readString, readSymbol, readSymbol, readTimestamp, readTimestamp, readUndefined, readUndefined, skipName, skipValue

    Methods inherited from class Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • DepthLimitedJsonReader

      public DepthLimitedJsonReader(@Nonnull String json, int maxDepth)
  • Method Details

    • readStartDocument

      public void readStartDocument()
      Specified by:
      readStartDocument in interface org.bson.BsonReader
      Overrides:
      readStartDocument in class org.bson.AbstractBsonReader
    • readStartArray

      public void readStartArray()
      Specified by:
      readStartArray in interface org.bson.BsonReader
      Overrides:
      readStartArray in class org.bson.AbstractBsonReader
    • readEndDocument

      public void readEndDocument()
      Specified by:
      readEndDocument in interface org.bson.BsonReader
      Overrides:
      readEndDocument in class org.bson.AbstractBsonReader
    • readEndArray

      public void readEndArray()
      Specified by:
      readEndArray in interface org.bson.BsonReader
      Overrides:
      readEndArray in class org.bson.AbstractBsonReader