-
Notifications
You must be signed in to change notification settings - Fork 54
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
Consider adding lifetime to byte buffer reference passed into load_pdf_from_bytes #63
Comments
Hi @Lampyrida, Good to hear from you and thank you for reporting this bug. I'm very sorry about this - this is entirely an oversight on my part. In addition to the lifetime mismatch, I'm concerned about what might happen if the data in the byte buffer was mutated "behind Pdfium's back", so to speak. (This would require unsafe code, but it's not impossible.) The safest way of guaranteeing both lifetime validity and data immutability is for
This would be less convenient when working with byte buffers loaded via the Let me think about this over the next day or two. I'd welcome any further thoughts you have. |
That's all good! I appreciate all the effort you have put into this library in the first place. You bring up a great point regarding the risk of mutations also. Having the I'm still somewhat new to Rust so not 100% sure this would work, but perhaps we can support both ownership and references by having |
Yes, a I have added a static lifetime requirement to the byte slice passed into I have pushed a commit that makes these small changes. If you could check to make sure they work for you, that'd be great. You will need to add |
That sounds very reasonable @ajrcarey. I just tried out the |
Very good. Having thought about it a bit more I'm going to rename the functions slightly to make their use clearer. These changes will be released as part of 0.7.26. Thanks again for raising this issue and helping me fix this bug. |
Updated |
Hi there!
I spent some time tracking down a bug that I tracked down to the following issue:
The
load_pdf_from_bytes
function wrapsFPDF_LoadMemDocument64
.FPDF_LoadMemDocument64
requires the byte buffer passed into it to remain valid for as long as the document is kept open. However, this is not enforced in any way by theload_pdf_from_bytes
function. I'm wondering if this is something we can address by introducing a lifetime associated with the buffer that ties it to the document.The text was updated successfully, but these errors were encountered: