[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
This commit is contained in:
Vlad Tsyrklevich 2018-04-02 15:52:19 -07:00 committed by James Zern
parent c909d53182
commit 978eec2507
4 changed files with 12 additions and 7 deletions

View File

@ -400,7 +400,9 @@ static void DitherRow(VP8Decoder* const dec) {
#define MACROBLOCK_VPOS(mb_y) ((mb_y) * 16) // vertical position of a MB #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. // 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; int ok = 1;
const VP8ThreadContext* const ctx = &dec->thread_ctx_; const VP8ThreadContext* const ctx = &dec->thread_ctx_;
const int cache_id = ctx->id_; const int cache_id = ctx->id_;
@ -647,7 +649,7 @@ static int InitThreadContext(VP8Decoder* const dec) {
} }
worker->data1 = dec; worker->data1 = dec;
worker->data2 = (void*)&dec->thread_ctx_.io_; worker->data2 = (void*)&dec->thread_ctx_.io_;
worker->hook = (WebPWorkerHook)FinishRow; worker->hook = FinishRow;
dec->num_caches_ = dec->num_caches_ =
(dec->filter_type_ > 0) ? MT_CACHE_LINES : MT_CACHE_LINES - 1; (dec->filter_type_ > 0) ? MT_CACHE_LINES : MT_CACHE_LINES - 1;
} else { } else {

View File

@ -361,7 +361,8 @@ static int EncodeAlpha(VP8Encoder* const enc,
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Main calls // 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_; const WebPConfig* config = enc->config_;
uint8_t* alpha_data = NULL; uint8_t* alpha_data = NULL;
size_t alpha_size = 0; size_t alpha_size = 0;
@ -394,7 +395,7 @@ void VP8EncInitAlpha(VP8Encoder* const enc) {
WebPGetWorkerInterface()->Init(worker); WebPGetWorkerInterface()->Init(worker);
worker->data1 = enc; worker->data1 = enc;
worker->data2 = NULL; worker->data2 = NULL;
worker->hook = (WebPWorkerHook)CompressAlphaJob; worker->hook = CompressAlphaJob;
} }
} }

View File

@ -434,7 +434,9 @@ typedef struct {
} SegmentJob; } SegmentJob;
// main work call // 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; int ok = 1;
if (!VP8IteratorIsDone(it)) { if (!VP8IteratorIsDone(it)) {
uint8_t tmp[32 + WEBP_ALIGN_CST]; uint8_t tmp[32 + WEBP_ALIGN_CST];
@ -462,7 +464,7 @@ static void InitSegmentJob(VP8Encoder* const enc, SegmentJob* const job,
WebPGetWorkerInterface()->Init(&job->worker); WebPGetWorkerInterface()->Init(&job->worker);
job->worker.data1 = job; job->worker.data1 = job;
job->worker.data2 = &job->it; job->worker.data2 = &job->it;
job->worker.hook = (WebPWorkerHook)DoSegmentsJob; job->worker.hook = DoSegmentsJob;
VP8IteratorInit(enc, &job->it); VP8IteratorInit(enc, &job->it);
VP8IteratorSetRow(&job->it, start_row); VP8IteratorSetRow(&job->it, start_row);
VP8IteratorSetCountDown(&job->it, (end_row - start_row) * enc->mb_w_); VP8IteratorSetCountDown(&job->it, (end_row - start_row) * enc->mb_w_);

View File

@ -1754,7 +1754,7 @@ WebPEncodingError VP8LEncodeStream(const WebPConfig* const config,
worker_interface->Init(worker); worker_interface->Init(worker);
worker->data1 = param; worker->data1 = param;
worker->data2 = NULL; worker->data2 = NULL;
worker->hook = (WebPWorkerHook)EncodeStreamHook; worker->hook = EncodeStreamHook;
} }
} }