From 978eec2507e3b5110bd1d2a408fa27a8f7e702cf Mon Sep 17 00:00:00 2001 From: Vlad Tsyrklevich Date: Mon, 2 Apr 2018 15:52:19 -0700 Subject: [PATCH] [CFI] Remove function pointer casts Control Flow Integrity [1] indirect call checking verifies that function pointers only call valid functions with a matching type signature. This change eliminates function pointer casts that were causing cfi-icall failures. [1] https://www.chromium.org/developers/testing/control-flow-integrity BUG=chromium:827826 Change-Id: I5db021d06390a6cefd670fdd2f0d34c9e530465e --- src/dec/frame_dec.c | 6 ++++-- src/enc/alpha_enc.c | 5 +++-- src/enc/analysis_enc.c | 6 ++++-- src/enc/vp8l_enc.c | 2 +- 4 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/dec/frame_dec.c b/src/dec/frame_dec.c index 514e85b5..a9d5430d 100644 --- a/src/dec/frame_dec.c +++ b/src/dec/frame_dec.c @@ -400,7 +400,9 @@ static void DitherRow(VP8Decoder* const dec) { #define MACROBLOCK_VPOS(mb_y) ((mb_y) * 16) // vertical position of a MB // Finalize and transmit a complete row. Return false in case of user-abort. -static int FinishRow(VP8Decoder* const dec, VP8Io* const io) { +static int FinishRow(void* arg1, void* arg2) { + VP8Decoder* const dec = (VP8Decoder*)arg1; + VP8Io* const io = (VP8Io*)arg2; int ok = 1; const VP8ThreadContext* const ctx = &dec->thread_ctx_; const int cache_id = ctx->id_; @@ -647,7 +649,7 @@ static int InitThreadContext(VP8Decoder* const dec) { } worker->data1 = dec; worker->data2 = (void*)&dec->thread_ctx_.io_; - worker->hook = (WebPWorkerHook)FinishRow; + worker->hook = FinishRow; dec->num_caches_ = (dec->filter_type_ > 0) ? MT_CACHE_LINES : MT_CACHE_LINES - 1; } else { diff --git a/src/enc/alpha_enc.c b/src/enc/alpha_enc.c index 7e8d87f2..dce9ca95 100644 --- a/src/enc/alpha_enc.c +++ b/src/enc/alpha_enc.c @@ -361,7 +361,8 @@ static int EncodeAlpha(VP8Encoder* const enc, //------------------------------------------------------------------------------ // Main calls -static int CompressAlphaJob(VP8Encoder* const enc, void* dummy) { +static int CompressAlphaJob(void* arg1, void* dummy) { + VP8Encoder* const enc = (VP8Encoder*)arg1; const WebPConfig* config = enc->config_; uint8_t* alpha_data = NULL; size_t alpha_size = 0; @@ -394,7 +395,7 @@ void VP8EncInitAlpha(VP8Encoder* const enc) { WebPGetWorkerInterface()->Init(worker); worker->data1 = enc; worker->data2 = NULL; - worker->hook = (WebPWorkerHook)CompressAlphaJob; + worker->hook = CompressAlphaJob; } } diff --git a/src/enc/analysis_enc.c b/src/enc/analysis_enc.c index 08f471f5..a47ff7d4 100644 --- a/src/enc/analysis_enc.c +++ b/src/enc/analysis_enc.c @@ -434,7 +434,9 @@ typedef struct { } SegmentJob; // main work call -static int DoSegmentsJob(SegmentJob* const job, VP8EncIterator* const it) { +static int DoSegmentsJob(void* arg1, void* arg2) { + SegmentJob* const job = (SegmentJob*)arg1; + VP8EncIterator* const it = (VP8EncIterator*)arg2; int ok = 1; if (!VP8IteratorIsDone(it)) { uint8_t tmp[32 + WEBP_ALIGN_CST]; @@ -462,7 +464,7 @@ static void InitSegmentJob(VP8Encoder* const enc, SegmentJob* const job, WebPGetWorkerInterface()->Init(&job->worker); job->worker.data1 = job; job->worker.data2 = &job->it; - job->worker.hook = (WebPWorkerHook)DoSegmentsJob; + job->worker.hook = DoSegmentsJob; VP8IteratorInit(enc, &job->it); VP8IteratorSetRow(&job->it, start_row); VP8IteratorSetCountDown(&job->it, (end_row - start_row) * enc->mb_w_); diff --git a/src/enc/vp8l_enc.c b/src/enc/vp8l_enc.c index aeb52f38..2b3f3486 100644 --- a/src/enc/vp8l_enc.c +++ b/src/enc/vp8l_enc.c @@ -1754,7 +1754,7 @@ WebPEncodingError VP8LEncodeStream(const WebPConfig* const config, worker_interface->Init(worker); worker->data1 = param; worker->data2 = NULL; - worker->hook = (WebPWorkerHook)EncodeStreamHook; + worker->hook = EncodeStreamHook; } }