Attempt to make GetInfo safer

This commit is contained in:
Matt Nadareski
2025-01-05 22:55:03 -05:00
parent 6ca59a3170
commit 8129d76d78
3 changed files with 19 additions and 21 deletions

View File

@@ -60,15 +60,6 @@ namespace SabreTools.FileTypes
}
}
/// <summary>
/// Retrieve file information for a single stream
/// </summary>
/// <param name="input">Stream to get information from</param>
/// <param name="hashes">Hashes to include in the information</param>
/// <returns>Populated BaseFile object if success, null on error</returns>
public static BaseFile GetInfo(Stream? input, HashType[] hashes)
=> GetInfo(input, size: -1, hashes, keepReadOpen: false);
/// <summary>
/// Retrieve file information for a single stream
/// </summary>
@@ -105,9 +96,16 @@ namespace SabreTools.FileTypes
try
{
// If we want to automatically set the size
if (size == -1)
size = input.Length;
try
{
// If we want to automatically set the size
if (size == -1)
size = input.Length;
}
catch
{
// Don't set the length if the stream doesn't support it
}
// Run the hashing on the input stream
var hashDict = HashTool.GetStreamHashes(input, hashes);