{"action":"closed","issue":{"url":"https://api.github.com/repos/devongovett/pdfkit/issues/362","labels_url":"https://api.github.com/repos/devongovett/pdfkit/issues/362/labels{/name}","comments_url":"https://api.github.com/repos/devongovett/pdfkit/issues/362/comments","events_url":"https://api.github.com/repos/devongovett/pdfkit/issues/362/events","html_url":"https://github.com/devongovett/pdfkit/issues/362","id":54523878,"number":362,"title":"imageRegistry Key could be very large when using a base64 data uri","user":{"login":"weswam","id":4452298,"avatar_url":"https://avatars.githubusercontent.com/u/4452298?v=3","gravatar_id":"","url":"https://api.github.com/users/weswam","html_url":"https://github.com/weswam","followers_url":"https://api.github.com/users/weswam/followers","following_url":"https://api.github.com/users/weswam/following{/other_user}","gists_url":"https://api.github.com/users/weswam/gists{/gist_id}","starred_url":"https://api.github.com/users/weswam/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/weswam/subscriptions","organizations_url":"https://api.github.com/users/weswam/orgs","repos_url":"https://api.github.com/users/weswam/repos","events_url":"https://api.github.com/users/weswam/events{/privacy}","received_events_url":"https://api.github.com/users/weswam/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-01-16T00:12:35Z","updated_at":"2015-03-19T01:07:19Z","closed_at":"2015-03-19T01:07:19Z","body":"Within the images mixin the \"src\" variable can be passed a path string, base64 data uri, or a buffer.\r\n\r\nThe 'src' variable is then used as the key within the imageRegistry object to store the image object for future reference.\r\n\r\nIn the case of a buffer being passed the imageRegistry is never invoked.\r\n\r\nIn the case of a path string being set in the 'src' variable there is no issue.\r\n\r\nThere is a potential issue when setting a base63 data uri in the 'src' variable though.\r\n\r\nWhen some provides a base64 data uri the entire string contains the image data and that image data is being used in the key as well. So for example lets say the base64 data of a image is 200kb that 200kb worth of data is being embed in the pdf and that image object is then being stored in the imageRegistry using a key that also contains the 200kb worth of image data. It appears this may be using more memory than is needed.\r\n\r\nA proposed fix is to hash the data portion of the base64 data uri and use that hash as the key. To check if a image already exists in the imageRegistry prior to inserting it again it could hash the incoming data portion of the proposed new image and check to see if it already exists. This would prevent storing the entire image data within the key while also maintaining the ability to check for the existence of an image.\r\n\r\nI am happy to work on this and do a pull request when complete. I just wanted to run this by the group for review and input first."}}