Skip to content

Error‐Handling | Safety

Paul Hirch edited this page May 13, 2024 · 1 revision

Read

  • BinaryViewReader.LengthPrefixMaxValue { get; set; } = long.MaxValue;
    If a LengthPrefix above this value is read, an InvalidDataException will be thrown. Useful to fail fast on corrupted data, opposed to having the program hang on trying to read gigabytes of wrong data.

  • BinaryViewReader.ValidateNotEndOfStream { get; set; } = true;
    Throw an EndOfStreamException on attempt to read beyond end of stream.

Write

  • BinaryViewWriter.ValidateLengthPrefix { get; set; } = true;
    Gets or Sets a value indicating whether to ensure that the writen value fits in the LengthPrefix type range.
    If undetected, this will corrupt your stream, attempts to later read any data after will probably fail.

  • BinaryViewWriter.ValidateEncoding { get; set; } = false;
    Gets or Sets a value indicating whether that the string will still be the same when read again with the same encoding.
    This check is relatively expensive and is only useful when using Encodings with a limited character set like Encoding.ASCII.
    A failure here will not result in a corrupted stream, only the read string will have an incorrect value.

  • BinaryViewWriter.ValidateTerminatedString { get; set; } = true;
    Gets or Sets a value indicating whether WriteTerminatedString() should check, if the string contains escape characters.
    If undetected, this will corrupt your stream, later attempts to read this string or any data after will probably fail.

Clone this wiki locally