Package org.stellar.sdk.xdr
Class XdrDataInputStream
java.lang.Object
java.io.InputStream
java.io.FilterInputStream
java.io.DataInputStream
org.stellar.sdk.xdr.XdrDataInputStream
- All Implemented Interfaces:
Closeable,DataInput,AutoCloseable
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intDefault maximum decoding depth to prevent stack overflow from deeply nested structures. -
Constructor Summary
ConstructorsConstructorDescriptionCreates a XdrDataInputStream that uses the specified underlying InputStream. -
Method Summary
Modifier and TypeMethodDescriptionintReturns the remaining input length if known, -1 otherwise.intread()double[]Deprecated.This method does not validate the array length and may cause OutOfMemoryError or NegativeArraySizeException with untrusted input.float[]Deprecated.This method does not validate the array length and may cause OutOfMemoryError or NegativeArraySizeException with untrusted input.int[]Deprecated.This method does not validate the array length and may cause OutOfMemoryError or NegativeArraySizeException with untrusted input.voidreadPaddedData(byte[] b, int off, int len) Reads exactly len bytes of XDR opaque/string data, handling short reads, then reads and validates padding bytes to maintain 4-byte alignment.booleanReads an XDR boolean value from the stream.voidsetMaxInputLen(int maxInputLen) Maximum input length, -1 if unknown.Methods inherited from class java.io.DataInputStream
read, read, readBoolean, readByte, readChar, readDouble, readFloat, readFully, readFully, readInt, readLine, readLong, readShort, readUnsignedByte, readUnsignedShort, readUTF, readUTF, skipBytesMethods inherited from class java.io.FilterInputStream
available, close, mark, markSupported, reset, skipMethods inherited from class java.io.InputStream
nullInputStream, readAllBytes, readNBytes, readNBytes, skipNBytes, transferTo
-
Field Details
-
DEFAULT_MAX_DEPTH
public static final int DEFAULT_MAX_DEPTHDefault maximum decoding depth to prevent stack overflow from deeply nested structures.- See Also:
-
-
Constructor Details
-
XdrDataInputStream
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
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.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.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.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
- Overrides:
readin classFilterInputStream- Throws:
IOException
-
readPaddedData
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 readoff- the start offset in array b at which the data is writtenlen- 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.
-