Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: File Cache Equality Check is Broken #1545

Open
utanapishtim opened this issue Aug 12, 2024 · 0 comments
Open

Bug: File Cache Equality Check is Broken #1545

utanapishtim opened this issue Aug 12, 2024 · 0 comments

Comments

@utanapishtim
Copy link
Contributor

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: #1544

Your environment

  • pdfkit version: latest
  • Node version: any
  • Browser version (if applicable): N/A
  • Operating System: any
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant