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

ensure we are passing through valid function pointers #1403

Merged

Conversation

kdt3rd
Copy link
Contributor

@kdt3rd kdt3rd commented May 9, 2023

libdeflate doesn't have the same fallback handling such that if someone resets the pointers, allocations later will crash

libdeflate doesn't have the same fallback handling such that if
someone resets the pointers, allocations later will crash

Signed-off-by: Kimball Thurston <kdt3rd@gmail.com>
@meshula
Copy link
Contributor

meshula commented May 9, 2023

Uggh, that's a bit gross. Not your fix, but the pattern in general. My app, SuperEXR does this

  • set libdeflate to use SuperEXR malloc/free
  • unzip something hooray
  • call openexr
  • unzip something, kaboom!

mitigation: save/restore the pointers

but sadly

  • set libdeflate to use SuperEXR malloc/free
  • threaded deflate something, oh this is taking a while
  • whatever, this is why crom gave us multithreading right? call openexr
  • kaboom!

wonder if we need to strip libdeflate down to almost nothing and completely tuck it under the covers? (and by wonder, I mean, maybe this is the only answer. Has the added benefit that we don't need to trouble package maintainers with how they can impose system deflate, if they wanna, they can just use the hooks you nicely provided and write a deflate adaptor themselves.)

@meshula
Copy link
Contributor

meshula commented May 12, 2023

If we force the export macros in libdeflate to static, and tag a small number of functions that libdeflate forget as static as well, we can completely hide libdeflate, and then we can be safe from someone set a memory handler on their copy of libdeflate.

since your change doesn't save and restore the pointers, only sets them, that would make our completely hidden libdeflate threadsafe.

also, I realize package managers love to be able to slap in their own version of everything, but the libdeflate license does not have a copyleft requirement that they be able to do so. Therefore I would say that we "canonically" don't support swapping in user libdeflate libraries.

Furthermore, we make security promises with OpenEXR, such as addressing CVEs. If we allow package managers to swap in libdeflate willy nilly we would violate our security promises.

So my proposal is that

  • we hard-smash the libdeflate API macros to static, and
  • completely seal the library within OpenEXR for thread safety, and
  • it is absolutely not an option to substitute user libdelfate for security reasons

@kdt3rd
Copy link
Contributor Author

kdt3rd commented May 16, 2023

ebiggers/libdeflate#312

@kdt3rd
Copy link
Contributor Author

kdt3rd commented May 16, 2023

I've gone the route of suggesting an alternate path upstream. libdeflate seems active enough that we may not want to vendor it in. Although if we do, I would debate making it such that malloc / free are not required for those structures in the first place (or integrated with the scratch buffer system in the core pipeline code.

Copy link
Member

@cary-ilm cary-ilm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@kdt3rd kdt3rd merged commit 62cf13c into AcademySoftwareFoundation:main May 19, 2023
@kdt3rd kdt3rd deleted the fix_deflate_alloc_pointer branch May 19, 2023 08:41
@cary-ilm cary-ilm added the v3.2.0 label Jul 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants