工具使用指南
修复后的 919 字节素材含三个 2 × 2 RGB 纯色块,不是绘制的漫画页。适合结构测试;旧版 750 字节文件包含无效占位内容,不适用于这些检查。
素材仅测试微型结构,不测试漫画质量、缩放、色彩管理或通用 PNG 解码能力;旧无效占位文件不能算有效图片。
边界
素材仅测试微型结构,不测试漫画质量、缩放、色彩管理或通用 PNG 解码能力;旧无效占位文件不能算有效图片。
如何使用
CBZ 示例漫画包 — 下载指定卡片为 sample-comic.cbz,先确认是 919 字节版本,再本地按顺序运行 Python 3 片段。不解压成员到磁盘、不打开图像查看器、不执行内嵌内容。
from pathlib import Path
import io, zipfile
with Path("sample-comic.cbz").open("rb") as f:
b = f.read(10001)
assert len(b) == 919, "This check requires the repaired 919-byte fixture"
z = zipfile.ZipFile(io.BytesIO(b))
assert z.namelist() == ["README.txt", "page1.png", "page2.png", "page3.png"]
assert sum(x.file_size for x in z.infolist()) < 1000
pages = [z.getinfo("page"+str(i)+".png") for i in (1,2,3)]
assert [x.file_size for x in pages] == [73,72,72]
print(len(z.infolist()), len(pages), [x.file_size for x in pages])结果
四个 ZIP 成员依次为 README.txt、page1.png、page2.png、page3.png。三个页面载荷大小为 73、72、72 字节,README 不是第四张图片。
如何使用
CBZ 示例漫画包 — 下载指定卡片为 sample-comic.cbz,先确认是 919 字节版本,再本地按顺序运行 Python 3 片段。不解压成员到磁盘、不打开图像查看器、不执行内嵌内容。
import struct, zlib
streams = []
for page in pages:
data = z.read(page)
assert data[:8] == b"\x89PNG\r\n\x1a\n"
offset = 8
chunks = []
idat = b""
while offset < len(data):
length = struct.unpack_from(">I", data, offset)[0]
assert offset+12+length <= len(data)
tag = data[offset+4:offset+8]
body = data[offset+8:offset+8+length]
crc = struct.unpack_from(">I", data, offset+8+length)[0]
assert crc == zlib.crc32(tag+body) & 0xffffffff
chunks.append(tag)
if tag == b"IHDR":
assert struct.unpack(">IIBBBBB",body) == (2,2,8,2,0,0,0)
if tag == b"IDAT": idat += body
offset += length+12
assert chunks == [b"IHDR",b"IDAT",b"IEND"]
streams.append(idat)
print(len(streams), "2x2 RGB8; chunk CRCs pass")结果
每页都有 PNG 签名及 IHDR、IDAT、IEND,所有块 CRC 匹配。IHDR 声明 2 × 2 像素、8 位真彩色、非交错;仅有 .png 名称不能证明有效。
如何使用
CBZ 示例漫画包 — 下载指定卡片为 sample-comic.cbz,先确认是 919 字节版本,再本地按顺序运行 Python 3 片段。不解压成员到磁盘、不打开图像查看器、不执行内嵌内容。
colors = [(255,0,0),(0,255,0),(0,0,255)]
for compressed, color in zip(streams, colors):
decoder = zlib.decompressobj()
rows = decoder.decompress(compressed,15)
assert decoder.eof and not decoder.unused_data and not decoder.unconsumed_tail
assert rows == (b"\0"+bytes(color)*2)*2
print(len(rows), color)
z.close()结果
有界 zlib 解码每页得到 14 字节:两行,每行一个零过滤字节和六个 RGB 字节。三页依次为纯红、纯绿、纯蓝。这是字节预期,不是实测查看器画面。
不能。这里只确认包与像素字节结构,没有测试浏览器渲染。