(SeraphCbImage): adjusted sanity checks.

This commit is contained in:
morkt
2022-05-03 13:43:57 +04:00
parent a96631b621
commit dd7ff36fb7

View File

@@ -124,6 +124,7 @@ namespace GameRes.Formats.Seraphim
{ {
// common case for 256-colors images // common case for 256-colors images
Signatures = new uint[] { 0x01004243, 0 }; Signatures = new uint[] { 0x01004243, 0 };
Extensions = new string[] { "CB", "CLB" };
} }
public override ImageMetaData ReadMetaData (IBinaryStream stream) public override ImageMetaData ReadMetaData (IBinaryStream stream)
@@ -133,18 +134,18 @@ namespace GameRes.Formats.Seraphim
return null; return null;
int colors = header.ToUInt16 (2); int colors = header.ToUInt16 (2);
int packed_size = header.ToInt32 (12); int packed_size = header.ToInt32 (12);
if (packed_size <= 0 || packed_size > stream.Length-0x10) if (packed_size <= 0 /*|| packed_size > stream.Length-0x10*/)
return null; return null;
uint width = header.ToUInt16 (8); int width = header.ToInt16 (8);
uint height = header.ToUInt16 (10); int height = header.ToInt16 (10);
if (0 == width || 0 == height) if (width <= 0 || height <= 0 || colors > 0x100)
return null; return null;
return new SeraphMetaData return new SeraphMetaData
{ {
OffsetX = header.ToInt16 (4), OffsetX = header.ToInt16 (4),
OffsetY = header.ToInt16 (6), OffsetY = header.ToInt16 (6),
Width = width, Width = (uint)width,
Height = height, Height = (uint)height,
BPP = 8, BPP = 8,
PackedSize = packed_size, PackedSize = packed_size,
Colors = colors, Colors = colors,
@@ -363,7 +364,7 @@ namespace GameRes.Formats.Seraphim
private byte[] UnpackBytes () // sub_403ED0 private byte[] UnpackBytes () // sub_403ED0
{ {
int total = m_width * m_height; int total = m_width * m_height;
var output = new byte[total]; var output = new byte[total + m_width];
int dst = 0; int dst = 0;
while ( dst < total ) while ( dst < total )
{ {
@@ -450,9 +451,9 @@ namespace GameRes.Formats.Seraphim
} }
else else
{ {
int v36 = m_input.ReadByte() | ((next & 0xF) << 8); int offset = m_input.ReadByte() | ((next & 0xF) << 8);
count = m_input.ReadByte() + 1; count = m_input.ReadByte() + 1;
int src = dst - 1 - v36; int src = dst - 1 - offset;
Binary.CopyOverlapped (output, src, dst, count); Binary.CopyOverlapped (output, src, dst, count);
} }
dst += count; dst += count;