From 6fa426711bfb7c7d8027878ff5c30940e50e3d82 Mon Sep 17 00:00:00 2001 From: amuliang <982632988@qq.com> Date: Mon, 18 Mar 2024 15:43:03 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8DIDAT=E5=9D=97=E5=A4=A7?= =?UTF-8?q?=E5=B0=8F=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- type/PNG.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/type/PNG.py b/type/PNG.py index dc1cddf..e2cc200 100644 --- a/type/PNG.py +++ b/type/PNG.py @@ -174,16 +174,22 @@ class PNG: changed = False b = False idat_append = [] + idat_length = 65445 + if len(idats) > 0: # 有时候IDAT块大小不是65445,默认用第一个IDAT块大小来检测之后的块 + idat_length = idats[0][1] for idat in idats: if not b: # 默认每个IDAT数据块最大为65445,如果出现一个数据块小于65445,说明数据块结束。如果后续又出现了IDAT数据块,则说明可能有异常数据 - if idat[1] < 65445: + if idat[1] < idat_length: b = True else: print('[x] 检测到异常IDAT数据块') idat_data = data[idat[0]: idat[0]+idat[1]] - idat_result = binascii.hexlify(zlib.decompress(idat_data)) # 究竟是不是要这样处理有待研究 - idat_append.append[idat_result] + try: + idat_result = binascii.hexlify(zlib.decompress(idat_data)) # 究竟是不是要这样处理有待研究 + except Exception as e: + idat_result = idat_data + idat_append.append(idat_result) return changed, data, idat_append @@ -196,7 +202,9 @@ class PNG: pixels_b = [] for y in range(height): for x in range(width): - r, g, b = image.getpixel((x, y)) + # result = image.getpixel((x, y)) + # print(result) + r, g, b, a = image.getpixel((x, y)) pixels_r.append(r) pixels_g.append(g) pixels_b.append(b)