Skip to content

Commit 899cfbf

Browse files
committed
debug: PNG全チャンクのtype/len/posをログ出力
1 parent ca2acd4 commit 899cfbf

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

‎src/Plugin/Extension/ImageHelper.cs‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ public static long GetPngSize(Stream st)
4545
}
4646

4747
bool flag = true;
48-
while (flag)
48+
int chunkCount = 0;
49+
while (flag && chunkCount++ < 1000)
4950
{
5051
byte[] widthBytes = new byte[4];
5152
st.Read(widthBytes, 0, 4);
@@ -54,14 +55,18 @@ public static long GetPngSize(Stream st)
5455
byte[] heightBytes = new byte[4];
5556
st.Read(heightBytes, 0, 4);
5657
int chunkType = BitConverter.ToInt32(heightBytes, 0);
58+
string typeStr = System.Text.Encoding.ASCII.GetString(heightBytes);
59+
Logger.LogDebug($" chunk[{chunkCount}]: type={typeStr}(0x{chunkType:X8}) len={chunkLength} pos={st.Position - 8}");
5760
if (chunkType == IEND_MAGIC) flag = false;
5861
if (chunkLength + 4 > st.Length - st.Position)
5962
{
6063
st.Seek(position, SeekOrigin.Begin);
61-
Logger.LogDebug($"GetPngSize: overflow chunkType=0x{chunkType:X8} chunkLen={chunkLength} remaining={st.Length - st.Position}");
64+
Logger.LogDebug($"GetPngSize: overflow chunkType=0x{chunkType:X8}({typeStr}) chunkLen={chunkLength} remaining={st.Length - st.Position}");
6265
return 0L;
6366
}
6467
st.Seek(chunkLength + 4, SeekOrigin.Current);
68+
}
69+
st.Seek(chunkLength + 4, SeekOrigin.Current);
6570
if (chunkType == IEND_MAGIC) Logger.LogDebug($"GetPngSize: found IEND at pos={st.Position}");
6671
}
6772

0 commit comments

Comments
 (0)