lucach / meta-png

JavaScript library to store and retrieve metadata in PNG files
27 stars 2 forks source link

Library corrupts PNG footer/end #7

Open drewlustro opened 1 year ago

drewlustro commented 1 year ago

Hello!

Thank you for the best JS library for writing PNG metadata!

I'm experiencing some image corruption when storing metadata.

Is there a specific version of node I should use to avoid this?

node --version
v16.14.0

Original

achiote

Metadata

achiote-metadata

lucach commented 1 year ago

Hi, I don't seem to be able to reproduce that just by downloading the image you added as an attachment, but I think uploading it to GitHub might have altered it.

Could you try to attach the original one here as a file (e.g., by adding it to a zip archive)? And could you also provide the snippet of code that generates the corrupted PNG?

drewlustro commented 1 year ago

Sure!

import { addMetadata } from 'meta-png';
import fs from 'node:fs';

const filePath = 'example.png'
const filePath2 = 'example-metadata.png'

const PNGUint8Array = new Uint8Array(fs.readFileSync(filePath));
const modified = addMetadata(modified, 'hello', 'world');
fs.writeFileSync(filePath2, modified);

achiote-corrupt-example.zip

lucach commented 1 year ago

I still cannot reproduce this. The node version should not matter that much, but I've tried to use exactly the same 16.14.0 as you have, and the image is generated just fine.

I assume the snippet you posted is not the actual code (well, first of all because it contains a typo -- using modified as an argument to addMetadata). Judging from the image in the archive, you seem to be adding several key-value pairs. Anyway, I've also tried that locally, and it works as expected.

The only thing that I can tell is that your file achiote-metadata.png is even smaller than the original one. The last ~1KB of the file is entirely missing, as if the file was truncated while writing. Can you reproduce the error consistently (does it always happen)? Does it also happen in a different environment (e.g., a different disk, a different machine)?