Browse Source

Fix embedding extraction for files with multiple chunks

pull/46/head
coomdev 2 years ago
parent
commit
5331ee3184
  1. 2
      main.meta.js
  2. 10
      main.user.js
  3. 9
      src/pngv3.ts

2
main.meta.js

@ -1,7 +1,7 @@
// ==UserScript== // ==UserScript==
// @name PNGExtraEmbed // @name PNGExtraEmbed
// @namespace https://coom.tech/ // @namespace https://coom.tech/
// @version 0.173 // @version 0.174
// @description uhh // @description uhh
// @author You // @author You
// @match https://boards.4channel.org/* // @match https://boards.4channel.org/*

10
main.user.js

@ -1,7 +1,7 @@
// ==UserScript== // ==UserScript==
// @name PNGExtraEmbed // @name PNGExtraEmbed
// @namespace https://coom.tech/ // @namespace https://coom.tech/
// @version 0.173 // @version 0.174
// @description uhh // @description uhh
// @author You // @author You
// @match https://boards.4channel.org/* // @match https://boards.4channel.org/*
@ -81,7 +81,7 @@
var define_BUILD_VERSION_default; var define_BUILD_VERSION_default;
var init_define_BUILD_VERSION = __esm({ var init_define_BUILD_VERSION = __esm({
"<define:BUILD_VERSION>"() { "<define:BUILD_VERSION>"() {
define_BUILD_VERSION_default = [0, 173]; define_BUILD_VERSION_default = [0, 174];
} }
}); });
@ -14002,6 +14002,7 @@
var extract = async (png) => { var extract = async (png) => {
const reader = BufferReadStream(png).getReader(); const reader = BufferReadStream(png).getReader();
const sneed = new PNGDecoder(reader); const sneed = new PNGDecoder(reader);
const ret = [];
try { try {
for await (const [name, chunk, crc, offset] of sneed.chunks()) { for await (const [name, chunk, crc, offset] of sneed.chunks()) {
let buff; let buff;
@ -14009,12 +14010,13 @@
case "tEXt": case "tEXt":
buff = await chunk(); buff = await chunk();
if (buff.slice(4, 4 + CUM3.length).equals(CUM3)) { if (buff.slice(4, 4 + CUM3.length).equals(CUM3)) {
return await decodeCoom3Payload(buff.slice(4 + CUM3.length)); const k = await decodeCoom3Payload(buff.slice(4 + CUM3.length));
ret.push(...k.filter((e) => e).map((e) => e));
} }
break; break;
case "IDAT": case "IDAT":
case "IEND": case "IEND":
return; return ret;
default: default:
break; break;
} }

9
src/pngv3.ts

@ -1,5 +1,5 @@
import { Buffer } from "buffer"; import { Buffer } from "buffer";
import type { ImageProcessor } from "./main"; import type { EmbeddedFile, ImageProcessor } from "./main";
import { PNGDecoder, PNGEncoder } from "./png"; import { PNGDecoder, PNGEncoder } from "./png";
import { buildPeeFile, decodeCoom3Payload, fireNotification, uploadFiles } from "./utils"; import { buildPeeFile, decodeCoom3Payload, fireNotification, uploadFiles } from "./utils";
@ -18,6 +18,8 @@ const BufferReadStream = (b: Buffer) => {
const extract = async (png: Buffer) => { const extract = async (png: Buffer) => {
const reader = BufferReadStream(png).getReader(); const reader = BufferReadStream(png).getReader();
const sneed = new PNGDecoder(reader); const sneed = new PNGDecoder(reader);
const ret: EmbeddedFile[] = [];
try { try {
for await (const [name, chunk, crc, offset] of sneed.chunks()) { for await (const [name, chunk, crc, offset] of sneed.chunks()) {
let buff: Buffer; let buff: Buffer;
@ -26,13 +28,14 @@ const extract = async (png: Buffer) => {
case 'tEXt': case 'tEXt':
buff = await chunk(); buff = await chunk();
if (buff.slice(4, 4 + CUM3.length).equals(CUM3)) { if (buff.slice(4, 4 + CUM3.length).equals(CUM3)) {
return await decodeCoom3Payload(buff.slice(4 + CUM3.length)); const k = await decodeCoom3Payload(buff.slice(4 + CUM3.length));
ret.push(...k.filter(e => e).map(e => e as EmbeddedFile));
} }
break; break;
case 'IDAT': case 'IDAT':
// eslint-disable-next-line no-fallthrough // eslint-disable-next-line no-fallthrough
case 'IEND': case 'IEND':
return; return ret;
// eslint-disable-next-line no-fallthrough // eslint-disable-next-line no-fallthrough
default: default:
break; break;

Loading…
Cancel
Save