Length can throw on read-forward streams

This commit is contained in:
Matt Nadareski
2024-11-28 22:24:37 -05:00
parent c06d8151e6
commit 25c0d036f2
69 changed files with 68 additions and 69 deletions

View File

@@ -12,7 +12,7 @@ namespace SabreTools.Serialization.Deserializers
public override MediaKeyBlock? Deserialize(Stream? data)
{
// If the data is invalid
if (data == null || data.Length == 0 || !data.CanRead)
if (data == null || !data.CanRead)
return null;
// If the offset is out of bounds

View File

@@ -12,7 +12,7 @@ namespace SabreTools.Serialization.Deserializers
public override SVM? Deserialize(Stream? data)
{
// If the data is invalid
if (data == null || data.Length == 0 || !data.CanRead)
if (data == null || !data.CanRead)
return null;
// If the offset is out of bounds

View File

@@ -12,7 +12,7 @@ namespace SabreTools.Serialization.Deserializers
public override Archive? Deserialize(Stream? data)
{
// If the data is invalid
if (data == null || data.Length == 0 || !data.CanRead)
if (data == null || !data.CanRead)
return null;
// If the offset is out of bounds

View File

@@ -14,7 +14,7 @@ namespace SabreTools.Serialization.Deserializers
public override BspFile? Deserialize(Stream? data)
{
// If the data is invalid
if (data == null || data.Length == 0 || !data.CanRead)
if (data == null || !data.CanRead)
return null;
// If the offset is out of bounds

View File

@@ -14,7 +14,7 @@ namespace SabreTools.Serialization.Deserializers
public override Binary? Deserialize(Stream? data)
{
// If the data is invalid
if (data == null || data.Length == 0 || !data.CanRead)
if (data == null || !data.CanRead)
return null;
// If the offset is out of bounds

View File

@@ -13,7 +13,7 @@ namespace SabreTools.Serialization.Deserializers
public override Header? Deserialize(Stream? data)
{
// If the data is invalid
if (data == null || data.Length == 0 || !data.CanRead)
if (data == null || !data.CanRead)
return null;
// If the offset is out of bounds

View File

@@ -11,7 +11,7 @@ namespace SabreTools.Serialization.Deserializers
public override Models.N3DS.CIA? Deserialize(Stream? data)
{
// If the data is invalid
if (data == null || data.Length == 0 || !data.CanRead)
if (data == null || !data.CanRead)
return null;
// If the offset is out of bounds

View File

@@ -13,7 +13,7 @@ namespace SabreTools.Serialization.Deserializers
public override Models.CueSheets.CueSheet? Deserialize(Stream? data)
{
// If the data is invalid
if (data == null || data.Length == 0 || !data.CanRead)
if (data == null || !data.CanRead)
return null;
// If the offset is out of bounds

View File

@@ -12,7 +12,7 @@ namespace SabreTools.Serialization.Deserializers
public override MetadataFile? Deserialize(Stream? data)
{
// If the data is invalid
if (data == null || data.Length == 0 || !data.CanRead)
if (data == null || !data.CanRead)
return null;
// If the offset is out of bounds

View File

@@ -11,7 +11,7 @@ namespace SabreTools.Serialization.Deserializers
public override Models.GCF.File? Deserialize(Stream? data)
{
// If the data is invalid
if (data == null || data.Length == 0 || !data.CanRead)
if (data == null || !data.CanRead)
return null;
// If the offset is out of bounds

View File

@@ -10,7 +10,7 @@ namespace SabreTools.Serialization.Deserializers
public override Models.IRD.File? Deserialize(Stream? data)
{
// If the data is invalid
if (data == null || data.Length == 0 || !data.CanRead)
if (data == null || !data.CanRead)
return null;
// If the offset is out of bounds

View File

@@ -11,7 +11,7 @@ namespace SabreTools.Serialization.Deserializers
public override Archive? Deserialize(Stream? data)
{
// If the data is invalid
if (data == null || data.Length == 0 || !data.CanRead)
if (data == null || !data.CanRead)
return null;
// If the offset is out of bounds

View File

@@ -14,7 +14,7 @@ namespace SabreTools.Serialization.Deserializers
public override Cabinet? Deserialize(Stream? data)
{
// If the data is invalid
if (data == null || data.Length == 0 || !data.CanRead)
if (data == null || !data.CanRead)
return null;
// If the offset is out of bounds

View File

@@ -13,7 +13,7 @@ namespace SabreTools.Serialization.Deserializers
public override Executable? Deserialize(Stream? data)
{
// If the data is invalid
if (data == null || data.Length == 0 || !data.CanRead)
if (data == null || !data.CanRead)
return null;
// If the offset is out of bounds

View File

@@ -12,7 +12,7 @@ namespace SabreTools.Serialization.Deserializers
public override Executable? Deserialize(Stream? data)
{
// If the data is invalid
if (data == null || data.Length == 0 || !data.CanRead)
if (data == null || !data.CanRead)
return null;
// If the offset is out of bounds

View File

@@ -13,7 +13,7 @@ namespace SabreTools.Serialization.Deserializers
public override Cabinet? Deserialize(Stream? data)
{
// If the data is invalid
if (data == null || data.Length == 0 || !data.CanRead)
if (data == null || !data.CanRead)
return null;
// If the offset is out of bounds

View File

@@ -14,7 +14,7 @@ namespace SabreTools.Serialization.Deserializers
public override Archive? Deserialize(Stream? data)
{
// If the data is invalid
if (data == null || data.Length == 0 || !data.CanRead)
if (data == null || !data.CanRead)
return null;
// If the offset is out of bounds

View File

@@ -13,7 +13,7 @@ namespace SabreTools.Serialization.Deserializers
public override Cart? Deserialize(Stream? data)
{
// If the data is invalid
if (data == null || data.Length == 0 || !data.CanRead)
if (data == null || !data.CanRead)
return null;
// If the offset is out of bounds

View File

@@ -12,7 +12,7 @@ namespace SabreTools.Serialization.Deserializers
public override Models.NCF.File? Deserialize(Stream? data)
{
// If the data is invalid
if (data == null || data.Length == 0 || !data.CanRead)
if (data == null || !data.CanRead)
return null;
// If the offset is out of bounds

View File

@@ -12,7 +12,7 @@ namespace SabreTools.Serialization.Deserializers
public override Executable? Deserialize(Stream? data)
{
// If the data is invalid
if (data == null || data.Length == 0 || !data.CanRead)
if (data == null || !data.CanRead)
return null;
// If the offset is out of bounds

View File

@@ -12,7 +12,7 @@ namespace SabreTools.Serialization.Deserializers
public override Cart? Deserialize(Stream? data)
{
// If the data is invalid
if (data == null || data.Length == 0 || !data.CanRead)
if (data == null || !data.CanRead)
return null;
// If the offset is out of bounds

View File

@@ -11,7 +11,7 @@ namespace SabreTools.Serialization.Deserializers
public override Models.PAK.File? Deserialize(Stream? data)
{
// If the data is invalid
if (data == null || data.Length == 0 || !data.CanRead)
if (data == null || !data.CanRead)
return null;
// If the offset is out of bounds

View File

@@ -12,7 +12,7 @@ namespace SabreTools.Serialization.Deserializers
public override Archive? Deserialize(Stream? data)
{
// If the data is invalid
if (data == null || data.Length == 0 || !data.CanRead)
if (data == null || !data.CanRead)
return null;
// If the offset is out of bounds

View File

@@ -15,7 +15,7 @@ namespace SabreTools.Serialization.Deserializers
public override DiscInformation? Deserialize(Stream? data)
{
// If the data is invalid
if (data == null || data.Length == 0 || !data.CanRead)
if (data == null || !data.CanRead)
return null;
// If the offset is out of bounds

View File

@@ -17,7 +17,7 @@ namespace SabreTools.Serialization.Deserializers
public override Archive? Deserialize(Stream? data)
{
// If the data is invalid
if (data == null || data.Length == 0 || !data.CanRead)
if (data == null || !data.CanRead)
return null;
// If the offset is out of bounds

View File

@@ -24,7 +24,7 @@ namespace SabreTools.Serialization.Deserializers
public AudioFile? Deserialize(Stream? data, long adjust)
{
// If the data is invalid
if (data == null || data.Length == 0 || !data.CanRead)
if (data == null || !data.CanRead)
return null;
// If the offset is out of bounds

View File

@@ -10,7 +10,7 @@ namespace SabreTools.Serialization.Deserializers
public override Playlist? Deserialize(Stream? data)
{
// If the data is invalid
if (data == null || data.Length == 0 || !data.CanRead)
if (data == null || !data.CanRead)
return null;
// If the offset is out of bounds

View File

@@ -17,7 +17,7 @@ namespace SabreTools.Serialization.Deserializers
public override Executable? Deserialize(Stream? data)
{
// If the data is invalid
if (data == null || data.Length == 0 || !data.CanRead)
if (data == null || !data.CanRead)
return null;
// If the offset is out of bounds

View File

@@ -12,7 +12,7 @@ namespace SabreTools.Serialization.Deserializers
public override Archive? Deserialize(Stream? data)
{
// If the data is invalid
if (data == null || data.Length == 0 || !data.CanRead)
if (data == null || !data.CanRead)
return null;
// If the offset is out of bounds

View File

@@ -10,7 +10,7 @@ namespace SabreTools.Serialization.Deserializers
public override Models.PlayStation3.SFB? Deserialize(Stream? data)
{
// If the data is invalid
if (data == null || data.Length == 0 || !data.CanRead)
if (data == null || !data.CanRead)
return null;
// If the offset is out of bounds

View File

@@ -10,7 +10,7 @@ namespace SabreTools.Serialization.Deserializers
public override Models.PlayStation3.SFO? Deserialize(Stream? data)
{
// If the data is invalid
if (data == null || data.Length == 0 || !data.CanRead)
if (data == null || !data.CanRead)
return null;
// If the offset is out of bounds

View File

@@ -13,7 +13,7 @@ namespace SabreTools.Serialization.Deserializers
public override Models.SGA.File? Deserialize(Stream? data)
{
// If the data is invalid
if (data == null || data.Length == 0 || !data.CanRead)
if (data == null || !data.CanRead)
return null;
// If the offset is out of bounds

View File

@@ -14,7 +14,7 @@ namespace SabreTools.Serialization.Deserializers
public override VbspFile? Deserialize(Stream? data)
{
// If the data is invalid
if (data == null || data.Length == 0 || !data.CanRead)
if (data == null || !data.CanRead)
return null;
// If the offset is out of bounds

View File

@@ -12,7 +12,7 @@ namespace SabreTools.Serialization.Deserializers
public override Models.VPK.File? Deserialize(Stream? data)
{
// If the data is invalid
if (data == null || data.Length == 0 || !data.CanRead)
if (data == null || !data.CanRead)
return null;
// If the offset is out of bounds

View File

@@ -12,7 +12,7 @@ namespace SabreTools.Serialization.Deserializers
public override Models.WAD3.File? Deserialize(Stream? data)
{
// If the data is invalid
if (data == null || data.Length == 0 || !data.CanRead)
if (data == null || !data.CanRead)
return null;
// If the offset is out of bounds

View File

@@ -11,7 +11,7 @@ namespace SabreTools.Serialization.Deserializers
public override Models.XZP.File? Deserialize(Stream? data)
{
// If the data is invalid
if (data == null || data.Length == 0 || !data.CanRead)
if (data == null || !data.CanRead)
return null;
// If the offset is out of bounds

View File

@@ -66,7 +66,7 @@ namespace SabreTools.Serialization.Wrappers
public static AACSMediaKeyBlock? Create(Stream? data)
{
// If the data is invalid
if (data == null || data.Length == 0 || !data.CanRead)
if (data == null || !data.CanRead)
return null;
try

View File

@@ -66,7 +66,7 @@ namespace SabreTools.Serialization.Wrappers
public static BDPlusSVM? Create(Stream? data)
{
// If the data is invalid
if (data == null || data.Length == 0 || !data.CanRead)
if (data == null || !data.CanRead)
return null;
try

View File

@@ -56,7 +56,7 @@ namespace SabreTools.Serialization.Wrappers
public static BFPK? Create(Stream? data)
{
// If the data is invalid
if (data == null || data.Length == 0 || !data.CanRead)
if (data == null || !data.CanRead)
return null;
try

View File

@@ -57,7 +57,7 @@ namespace SabreTools.Serialization.Wrappers
public static BSP? Create(Stream? data)
{
// If the data is invalid
if (data == null || data.Length == 0 || !data.CanRead)
if (data == null || !data.CanRead)
return null;
try

View File

@@ -72,7 +72,7 @@ namespace SabreTools.Serialization.Wrappers
public static CFB? Create(Stream? data)
{
// If the data is invalid
if (data == null || data.Length == 0 || !data.CanRead)
if (data == null || !data.CanRead)
return null;
try

View File

@@ -99,7 +99,7 @@ namespace SabreTools.Serialization.Wrappers
public static CHD? Create(Stream? data)
{
// If the data is invalid
if (data == null || data.Length == 0 || !data.CanRead)
if (data == null || !data.CanRead)
return null;
try

View File

@@ -57,7 +57,7 @@ namespace SabreTools.Serialization.Wrappers
public static CIA? Create(Stream? data)
{
// If the data is invalid
if (data == null || data.Length == 0 || !data.CanRead)
if (data == null || !data.CanRead)
return null;
try

View File

@@ -212,7 +212,7 @@ namespace SabreTools.Serialization.Wrappers
public static GCF? Create(Stream? data)
{
// If the data is invalid
if (data == null || data.Length == 0 || !data.CanRead)
if (data == null || !data.CanRead)
return null;
try

View File

@@ -56,7 +56,7 @@ namespace SabreTools.Serialization.Wrappers
public static IRD? Create(Stream? data)
{
// If the data is invalid
if (data == null || data.Length == 0 || !data.CanRead)
if (data == null || !data.CanRead)
return null;
try

View File

@@ -116,7 +116,7 @@ namespace SabreTools.Serialization.Wrappers
public static InstallShieldCabinet? Create(Stream? data)
{
// If the data is invalid
if (data == null || data.Length == 0 || !data.CanRead)
if (data == null || !data.CanRead)
return null;
try

View File

@@ -57,7 +57,7 @@ namespace SabreTools.Serialization.Wrappers
public static LinearExecutable? Create(Stream? data)
{
// If the data is invalid
if (data == null || data.Length == 0 || !data.CanRead)
if (data == null || !data.CanRead)
return null;
try

View File

@@ -56,7 +56,7 @@ namespace SabreTools.Serialization.Wrappers
public static MSDOS? Create(Stream? data)
{
// If the data is invalid
if (data == null || data.Length == 0 || !data.CanRead)
if (data == null || !data.CanRead)
return null;
try

View File

@@ -57,7 +57,7 @@ namespace SabreTools.Serialization.Wrappers
public static MicrosoftCabinet? Create(Stream? data)
{
// If the data is invalid
if (data == null || data.Length == 0 || !data.CanRead)
if (data == null || !data.CanRead)
return null;
try

View File

@@ -56,7 +56,7 @@ namespace SabreTools.Serialization.Wrappers
public static MoPaQ? Create(Stream? data)
{
// If the data is invalid
if (data == null || data.Length == 0 || !data.CanRead)
if (data == null || !data.CanRead)
return null;
try

View File

@@ -251,7 +251,7 @@ namespace SabreTools.Serialization.Wrappers
public static N3DS? Create(Stream? data)
{
// If the data is invalid
if (data == null || data.Length == 0 || !data.CanRead)
if (data == null || !data.CanRead)
return null;
try

View File

@@ -56,7 +56,7 @@ namespace SabreTools.Serialization.Wrappers
public static NCF? Create(Stream? data)
{
// If the data is invalid
if (data == null || data.Length == 0 || !data.CanRead)
if (data == null || !data.CanRead)
return null;
try

View File

@@ -57,7 +57,7 @@ namespace SabreTools.Serialization.Wrappers
public static NewExecutable? Create(Stream? data)
{
// If the data is invalid
if (data == null || data.Length == 0 || !data.CanRead)
if (data == null || !data.CanRead)
return null;
try

View File

@@ -64,7 +64,7 @@ namespace SabreTools.Serialization.Wrappers
public static Nitro? Create(Stream? data)
{
// If the data is invalid
if (data == null || data.Length == 0 || !data.CanRead)
if (data == null || !data.CanRead)
return null;
try

View File

@@ -64,7 +64,7 @@ namespace SabreTools.Serialization.Wrappers
public static PAK? Create(Stream? data)
{
// If the data is invalid
if (data == null || data.Length == 0 || !data.CanRead)
if (data == null || !data.CanRead)
return null;
try

View File

@@ -69,7 +69,7 @@ namespace SabreTools.Serialization.Wrappers
public static PFF? Create(Stream? data)
{
// If the data is invalid
if (data == null || data.Length == 0 || !data.CanRead)
if (data == null || !data.CanRead)
return null;
try

View File

@@ -64,7 +64,7 @@ namespace SabreTools.Serialization.Wrappers
public static PIC? Create(Stream? data)
{
// If the data is invalid
if (data == null || data.Length == 0 || !data.CanRead)
if (data == null || !data.CanRead)
return null;
try

View File

@@ -57,7 +57,7 @@ namespace SabreTools.Serialization.Wrappers
public static PKZIP? Create(Stream? data)
{
// If the data is invalid
if (data == null || data.Length == 0 || !data.CanRead)
if (data == null || !data.CanRead)
return null;
try

View File

@@ -56,7 +56,7 @@ namespace SabreTools.Serialization.Wrappers
public static PlayJAudioFile? Create(Stream? data)
{
// If the data is invalid
if (data == null || data.Length == 0 || !data.CanRead)
if (data == null || !data.CanRead)
return null;
try

View File

@@ -56,7 +56,7 @@ namespace SabreTools.Serialization.Wrappers
public static PlayJPlaylist? Create(Stream? data)
{
// If the data is invalid
if (data == null || data.Length == 0 || !data.CanRead)
if (data == null || !data.CanRead)
return null;
try

View File

@@ -803,7 +803,7 @@ namespace SabreTools.Serialization.Wrappers
public static PortableExecutable? Create(Stream? data)
{
// If the data is invalid
if (data == null || data.Length == 0 || !data.CanRead)
if (data == null || !data.CanRead)
return null;
try

View File

@@ -56,7 +56,7 @@ namespace SabreTools.Serialization.Wrappers
public static Quantum? Create(Stream? data)
{
// If the data is invalid
if (data == null || data.Length == 0 || !data.CanRead)
if (data == null || !data.CanRead)
return null;
try

View File

@@ -100,7 +100,7 @@ namespace SabreTools.Serialization.Wrappers
public static SGA? Create(Stream? data)
{
// If the data is invalid
if (data == null || data.Length == 0 || !data.CanRead)
if (data == null || !data.CanRead)
return null;
try

View File

@@ -57,7 +57,7 @@ namespace SabreTools.Serialization.Wrappers
public static VBSP? Create(Stream? data)
{
// If the data is invalid
if (data == null || data.Length == 0 || !data.CanRead)
if (data == null || !data.CanRead)
return null;
try

View File

@@ -127,7 +127,7 @@ namespace SabreTools.Serialization.Wrappers
public static VPK? Create(Stream? data)
{
// If the data is invalid
if (data == null || data.Length == 0 || !data.CanRead)
if (data == null || !data.CanRead)
return null;
try

View File

@@ -56,7 +56,7 @@ namespace SabreTools.Serialization.Wrappers
public static WAD3? Create(Stream? data)
{
// If the data is invalid
if (data == null || data.Length == 0 || !data.CanRead)
if (data == null || !data.CanRead)
return null;
try

View File

@@ -129,7 +129,7 @@ namespace SabreTools.Serialization.Wrappers
throw new ArgumentNullException(nameof(model));
if (data == null)
throw new ArgumentNullException(nameof(data));
if (data.Length == 0 || !data.CanSeek || !data.CanRead)
if (!data.CanSeek || !data.CanRead)
throw new ArgumentOutOfRangeException(nameof(data));
Model = model;

View File

@@ -89,7 +89,6 @@ namespace SabreTools.Serialization.Wrappers
try
{
var xmid = Deserializers.XMID.DeserializeString(data);
if (xmid == null)
return null;

View File

@@ -57,7 +57,7 @@ namespace SabreTools.Serialization.Wrappers
public static XZP? Create(Stream? data)
{
// If the data is invalid
if (data == null || data.Length == 0 || !data.CanRead)
if (data == null || !data.CanRead)
return null;
try