foliojs / pdfkit

A JavaScript PDF generation library for Node and the browser
http://pdfkit.org/
MIT License
9.92k stars 1.16k forks source link

Bug: File Cache Equality Check is Broken #1545

Open utanapishtim opened 3 months ago

utanapishtim commented 3 months ago

Bug Report

When a file is attached, pdfkit checks to see if an identical file has already been attached and reuses its reference to reduce the size of the resulting pdf. Currently the code for checking file equality is broken; in particular, the dates for modification and creation are compared by reference:

Line 107-115 of lib/mixins/attachments.js:

function isEqual(a, b) {
  return (
    a.Subtype === b.Subtype &&
    a.Params.CheckSum.toString() === b.Params.CheckSum.toString() &&
    a.Params.Size === b.Params.Size &&
    a.Params.CreationDate === b.Params.CreationDate &&
    a.Params.ModDate === b.Params.ModDate
  );
}

Should be:

function isEqual(a, b) {
  return (
    a.Subtype === b.Subtype &&
    a.Params.CheckSum.toString() === b.Params.CheckSum.toString() &&
    a.Params.Size === b.Params.Size &&
    a.Params.CreationDate.getTime() === b.Params.CreationDate.getTime() &&
    a.Params.ModDate.getTime() === b.Params.ModDate.getTime()
  );
}

Opened this PR to fix: https://github.com/foliojs/pdfkit/pull/1544

Your environment