Class XdrDataInputStream

All Implemented Interfaces:
Closeable, DataInput, AutoCloseable

public class XdrDataInputStream extends DataInputStream
  • Field Details

    • DEFAULT_MAX_DEPTH

      public static final int DEFAULT_MAX_DEPTH
      Default maximum decoding depth to prevent stack overflow from deeply nested structures.
      See Also:
  • Constructor Details

    • XdrDataInputStream

      public XdrDataInputStream(InputStream in)
      Creates a XdrDataInputStream that uses the specified underlying InputStream.
      Parameters:
      in - the specified input stream
  • Method Details

    • getRemainingInputLen

      public int getRemainingInputLen()
      Returns the remaining input length if known, -1 otherwise. This can be used to validate sizes before allocating memory.
      Returns:
      remaining input length, or -1 if unknown
    • readXdrBoolean

      public boolean readXdrBoolean() throws IOException
      Reads an XDR boolean value from the stream. Per RFC 4506, a boolean is encoded as an integer that must be 0 (FALSE) or 1 (TRUE).
      Returns:
      the boolean value
      Throws:
      IOException - if the value is not 0 or 1, or if an I/O error occurs
    • readIntArray

      @Deprecated public int[] readIntArray() throws IOException
      Deprecated.
      This method does not validate the array length and may cause OutOfMemoryError or NegativeArraySizeException with untrusted input. Use generated XDR type decoders instead which include proper validation.
      Throws:
      IOException
    • readFloatArray

      @Deprecated public float[] readFloatArray() throws IOException
      Deprecated.
      This method does not validate the array length and may cause OutOfMemoryError or NegativeArraySizeException with untrusted input. Use generated XDR type decoders instead which include proper validation.
      Throws:
      IOException
    • readDoubleArray

      @Deprecated public double[] readDoubleArray() throws IOException
      Deprecated.
      This method does not validate the array length and may cause OutOfMemoryError or NegativeArraySizeException with untrusted input. Use generated XDR type decoders instead which include proper validation.
      Throws:
      IOException
    • read

      public int read() throws IOException
      Overrides:
      read in class FilterInputStream
      Throws:
      IOException
    • readPaddedData

      public void readPaddedData(byte[] b, int off, int len) throws IOException
      Reads exactly len bytes of XDR opaque/string data, handling short reads, then reads and validates padding bytes to maintain 4-byte alignment. This method must be used instead of read(byte[], int, int) for opaque data to correctly handle short reads from the underlying stream.
      Parameters:
      b - the buffer into which the data is read
      off - the start offset in array b at which the data is written
      len - the number of bytes to read
      Throws:
      IOException - if an I/O error occurs or EOF is reached before reading len bytes
    • setMaxInputLen

      public void setMaxInputLen(int maxInputLen)
      Maximum input length, -1 if unknown. This is used to validate that the declared size of variable-length arrays/opaques doesn't exceed the remaining input length, preventing DoS attacks.