Skip to content

Commit 9a1718e

Browse files
fix: invalid reference png (#1120)
1 parent 1929c1f commit 9a1718e

4 files changed

Lines changed: 12 additions & 12 deletions

File tree

package-lock.json

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@
9494
"load-esm": "1.0.2",
9595
"local-pkg": "0.4.3",
9696
"lodash": "4.17.21",
97-
"looks-same": "10.0.0",
97+
"looks-same": "10.0.1",
9898
"micromatch": "4.0.5",
9999
"mocha": "10.2.0",
100100
"pirates": "4.0.7",

src/image.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ export class Image {
109109
sourceOffset += bytesToIterate;
110110
}
111111

112-
this._imgData = Buffer.from(imgData.buffer, 0, bufferPointer);
112+
this._imgData = imgData.subarray(0, bufferPointer);
113113
this._width = rect.width;
114114
this._height = rect.height;
115115
}

src/utils/eight-bit-rgba-to-png.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,20 +53,20 @@ export const convertRgbaToPng = (rgba: Buffer, width: number, height: number, co
5353
pointer = resultBuffer.writeUInt8(PNG_COMPRESSION_DEFLATE, pointer);
5454
pointer = resultBuffer.writeUInt8(PNG_FILTER_NO_FILTER, pointer);
5555
pointer = resultBuffer.writeUInt8(PNG_INTERLACE_NO_INTERLACE, pointer);
56-
const ihdrCrc = crc32(Buffer.from(resultBuffer.buffer, ihdrPointer, pointer - ihdrPointer));
56+
const ihdrCrc = crc32(resultBuffer.subarray(ihdrPointer, pointer));
5757
pointer = resultBuffer.writeUInt32BE(ihdrCrc, pointer);
5858

5959
// IDAT
6060
const idatPointer = (pointer = resultBuffer.writeUInt32BE(compressedData.length, pointer));
6161
pointer += resultBuffer.write("IDAT", idatPointer, "ascii");
6262
pointer += compressedData.copy(resultBuffer, pointer);
63-
const idatCrc = crc32(Buffer.from(resultBuffer.buffer, idatPointer, pointer - idatPointer));
63+
const idatCrc = crc32(resultBuffer.subarray(idatPointer, pointer));
6464
pointer = resultBuffer.writeUInt32BE(idatCrc, pointer);
6565

6666
// IEND (empty)
6767
const iendPointer = (pointer = resultBuffer.writeUInt32BE(0, pointer));
6868
pointer += resultBuffer.write("IEND", pointer, "ascii");
69-
const iendCrc = crc32(Buffer.from(resultBuffer.buffer, iendPointer, pointer - iendPointer));
69+
const iendCrc = crc32(resultBuffer.subarray(iendPointer, pointer));
7070
pointer = resultBuffer.writeUInt32BE(iendCrc, pointer);
7171

7272
if (pointer !== resultBuffer.byteLength) {

0 commit comments

Comments
 (0)