Skip to content

Commit

Permalink
Use safe decompression for MiniLZO to avoid possible stack corruption.
Browse files Browse the repository at this point in the history
  • Loading branch information
gibbed committed May 27, 2019
1 parent 05bfa5d commit 53c53bf
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
26 changes: 14 additions & 12 deletions projects/Gibbed.BorderlandsOz.FileFormats/SaveFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -360,12 +360,13 @@ public static SaveFile Deserialize(Stream input, Platform platform, DeserializeS
var actualUncompressedSize = (int)uncompressedSize;
var compressedSize = (int)(data.Length - 4);
var compressedBytes = data.ReadBytes(compressedSize);
var result = MiniLZO.LZO.Decompress(compressedBytes,
0,
(int)compressedSize,
uncompressedBytes,
0,
ref actualUncompressedSize);
var result = MiniLZO.LZO.DecompressSafe(
compressedBytes,
0,
(int)compressedSize,
uncompressedBytes,
0,
ref actualUncompressedSize);
if (result != MiniLZO.ErrorCode.Success)
{
throw new SaveCorruptionException(string.Format("LZO decompression failure ({0})", result));
Expand Down Expand Up @@ -425,12 +426,13 @@ public static SaveFile Deserialize(Stream input, Platform platform, DeserializeS
var actualUncompressedSize = blockUncompressedSize;
var compressedSize = (int)blockInfo.Item1;
var compressedBytes = data.ReadBytes(compressedSize);
var result = MiniLZO.LZO.Decompress(compressedBytes,
0,
compressedSize,
uncompressedBytes,
uncompressedOffset,
ref actualUncompressedSize);
var result = MiniLZO.LZO.DecompressSafe(
compressedBytes,
0,
compressedSize,
uncompressedBytes,
uncompressedOffset,
ref actualUncompressedSize);
if (result != MiniLZO.ErrorCode.Success)
{
throw new SaveCorruptionException(string.Format("LZO decompression failure ({0})",
Expand Down
2 changes: 1 addition & 1 deletion projects/VerifySaves/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ private static void Main(string[] args)
var uncompressedBytes = new byte[uncompressedSize];
var compressedSize = (int)(data.Length - 4);
var compressedBytes = data.ReadBytes(compressedSize);
var result = MiniLZO.LZO.Decompress(
var result = MiniLZO.LZO.DecompressSafe(
compressedBytes,
0,
compressedSize,
Expand Down

0 comments on commit 53c53bf

Please sign in to comment.