Skip to content

Commit

Permalink
Fix QL-Win#417: search acTL chunk by block, instead of byte-by-byte
Browse files Browse the repository at this point in the history
  • Loading branch information
xupefei committed Nov 1, 2018
1 parent 6768f44 commit 69c4662
Showing 1 changed file with 19 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -179,21 +179,37 @@ private static bool IsAnimatedPng(string path)
{
using (var br = new BinaryReader(new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)))
{
while (br.BaseStream.Length - br.BaseStream.Position >= 4)
if (br.BaseStream.Length < 8 + 4)
return false;

uint nextChunk = 8; // skip header

while (nextChunk > 0 && nextChunk < br.BaseStream.Length)
{
var window = br.ReadBytes(4);
br.BaseStream.Position = nextChunk;

var data_size = ToUInt32BE(br.ReadBytes(4)); // data size in BE

var window = br.ReadBytes(4); // label

if (window[0] == 'I' && window[1] == 'D' && window[2] == 'A' && window[3] == 'T')
return false;

if (window[0] == 'a' && window[1] == 'c' && window[2] == 'T' && window[3] == 'L')
return true;

br.BaseStream.Position -= 3;
// *[Data Size] + Data Size + Label + CRC
nextChunk += data_size + 4 + 4 + 4;
}

return false;
}

uint ToUInt32BE(byte[] data)
{
Array.Reverse(data);
return BitConverter.ToUInt32(data, 0);
}
}

private class FrameInfo
Expand Down

0 comments on commit 69c4662

Please sign in to comment.