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

reformat_libyuv: Add ignore CFI annotation #1507

Merged
merged 1 commit into from
Aug 18, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion src/reformat_libyuv.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,18 @@ unsigned int avifLibYUVVersion(void)
#pragma clang diagnostic pop
#endif

// libyuv is a C++ library and defines custom types (struct, enum, etc) in the libyuv namespace when the libyuv header files are
// included by C++ code. When accessed from a C library like libavif, via a function pointer, this leads to signature mismatches
// in the CFI sanitizers since libyuv itself, compiled as C++ code, has the types within the namespace and the C code has the
// types without the namespace. In order to avoid this CFI error, we tag some functions as an exception when being compiled with
// CFI enabled. For more details on clang's CFI see: https://clang.llvm.org/docs/ControlFlowIntegrity.html. For a simpler example
// of this bug, please see: https://github.com/vigneshvg/cpp_c_potential_cfi_bug
#if defined(__clang__)
#define IGNORE_CFI_ICALL __attribute__((no_sanitize("cfi-icall")))
#else
#define IGNORE_CFI_ICALL
#endif

//--------------------------------------------------------------------------------------------------
// libyuv API availability management

Expand Down Expand Up @@ -892,7 +904,7 @@ static avifResult avifImageDownshiftTo8bpc(const avifImage * image, avifImage *
return AVIF_RESULT_OK;
}

avifResult avifImageYUVToRGBLibYUV(const avifImage * image, avifRGBImage * rgb, avifBool reformatAlpha, avifBool * alphaReformattedWithLibYUV)
IGNORE_CFI_ICALL avifResult avifImageYUVToRGBLibYUV(const avifImage * image, avifRGBImage * rgb, avifBool reformatAlpha, avifBool * alphaReformattedWithLibYUV)
{
*alphaReformattedWithLibYUV = AVIF_FALSE;
if (rgb->depth != 8 || (image->depth != 8 && image->depth != 10 && image->depth != 12)) {
Expand Down
Loading