From patchwork Fri Jun 8 15:47:05 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derek Buitenhuis X-Patchwork-Id: 9324 Delivered-To: ffmpegpatchwork@gmail.com Received: by 2002:a02:11c:0:0:0:0:0 with SMTP id c28-v6csp1036021jad; Fri, 8 Jun 2018 08:55:39 -0700 (PDT) X-Google-Smtp-Source: ADUXVKKqHcHxI/F8GzZgkQQqkmg1bAZDFSAxWXJKkkLQf8yxXAZSmg/np4Y+sfiF1MAdR4QMQUmB X-Received: by 2002:adf:e152:: with SMTP id f18-v6mr5158117wri.42.1528473338924; Fri, 08 Jun 2018 08:55:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528473338; cv=none; d=google.com; s=arc-20160816; b=r5dbAy8iyP8x7HnfaCJC83FB/9b4QJjdBUx0lNqhJ9ElP8RhivsUWG63GpXYTjOjU2 Za/f0Lh+LH+KFeFaMdYpp9sjoDZHgtQorNEq9JN4waWmSZJx7CPfiB8vHEWKtG7xM0gc h0tMNq3Udkprj1dDuc5clVOHF6wDDfH8RnoPvSQGKDlddkSu6UwTAFlX5Rczre8ff3MH vjCzWhdaVB3/lFk+3Hrmwkkl0nX9hZxVJ+Zv6G12ustQw43xr96LJ+O+/y6Ui3LVjxD7 CDtyQ0MJ+AMAHQ5u/xGUnaio2tvDt6lpiyRwX4suYwGQJ/mAEMHmkYEKHOLxjnCvQ+VX yhrg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:message-id:date:to:from:dkim-signature :delivered-to:arc-authentication-results; bh=NovENS2kVdgVRffb2Heg6+jDc3w6Tg24C+srWF7VaK4=; b=Q+asnQGRAoqKy3oAFZkfrYoiAd8HAFBYUK24/Dbjj9dQ+jOtQehZK/DQ91N2E6dbil lhpQsmL7bTbqDK1MZblXoXADhySTlqybHCC/wiTaeFbkKGd7AzbCkFfdGuKVTtOnUjQA iZMkMDaca7/aFhop0f4sDPIBu3efHa9qJ9dVq5uzCUZnmZGPMqlJZxlbldlW62sN+dEY F6oeLkpCuJG8R5F3siswlneX8ySKhb7zIyxYKeGimsq6FQwp2sg4nV0IlSKS5/mIaTAd 7UAMn7uEJjECr0dixg7rtyP/TFGs7o/f54IOVFQ521SgO/MuHLsBfBo9CjXiC1XbWTRJ rqbQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=CVSE3x/N; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id t5-v6si31655468wrp.371.2018.06.08.08.55.38; Fri, 08 Jun 2018 08:55:38 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=CVSE3x/N; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 6EC23689AA1; Fri, 8 Jun 2018 18:54:48 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm0-f65.google.com (mail-wm0-f65.google.com [74.125.82.65]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id F14C768832E for ; Fri, 8 Jun 2018 18:54:41 +0300 (EEST) Received: by mail-wm0-f65.google.com with SMTP id e16-v6so4183951wmd.0 for ; Fri, 08 Jun 2018 08:55:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id; bh=D16rqmx31KK7x3UQ6zz1mbL9Lvz2ezw0+cxl8Oh3AdM=; b=CVSE3x/NUQmA5rix2Fnc6ItYgKlCwH3qiei31zM6e88OxExZl7wvONrEd10ObSN5vx alL4ooHndhja02oezfWX55tFTZZyyS26tGe6gfuwtKb3t9fSjrsB0s3rNDE9fi+XFqfH ea1TRxGQQHsh5a6T6Y2cNcOPStX+4xQfwk2OgXhsSiRcWCSvTTlVmb0xygWeYJqC+ztS ZfOoR3aZwHLW4kKUNULO2rF1Plh3GuHwZgCk2oktsd3J77j0pMtmDZfY4fq6e0rPSugn asXglu1KFnFYG1wfL5pOAUklH7rlkB4tgAgoEPQHDma8LTPzChJNOhNKx4Mpgiy0G9t+ 6GCA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id; bh=D16rqmx31KK7x3UQ6zz1mbL9Lvz2ezw0+cxl8Oh3AdM=; b=gmMjPUpiHwLlMafF3LQ1Rhu3FdbYUBxyBTFDaCrL7Qal4Gos9+S8qA2exZQ75etSZI UwDm522UYpchpz1iZddj3txdBRJ8NbPnW8gdrq8IOK8GBVCMgXo9EuJgxRrvFBadETA6 sa+DfE6XDDFeVOKZ65p1ktu1x5g4U8bOYXQMv+mCbEhr52lzeiAjUBXhrZvMjBIs9TP2 mkIjQb8bnGkEHzEOBO0+UKSAZ5BHD4+geSZ3uDK4dmJTy/yYvJxl7faVCKLr5Kt/gDWX JB1g//+XHmTiJIHTXz+Gc0RrpCoOSpyFa7lBlK8amOtutoUNGoo1NlLtD1iCZherKMD2 TnUQ== X-Gm-Message-State: APt69E1JuB7ND+aeu5fkRbCZBDU3CVStoWORDJOrMbluOlY8GS5hH6pd QsYUTE8ClUmQIKGRotEfbl2rfPvK X-Received: by 2002:a1c:3607:: with SMTP id d7-v6mr2079008wma.39.1528472837185; Fri, 08 Jun 2018 08:47:17 -0700 (PDT) Received: from localhost.localdomain ([81.2.162.105]) by smtp.gmail.com with ESMTPSA id v13-v6sm18620974wrq.43.2018.06.08.08.47.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 08 Jun 2018 08:47:15 -0700 (PDT) From: Derek Buitenhuis To: ffmpeg-devel@ffmpeg.org Date: Fri, 8 Jun 2018 16:47:05 +0100 Message-Id: <20180608154705.144075-1-derek.buitenhuis@gmail.com> X-Mailer: git-send-email 2.17.1 Subject: [FFmpeg-devel] [PATCH] pixdesc: Only check against valid entries when iterating over lists of enums X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Some of these enums have gaps in between their values, since they correspond to the values in various specs, instead of being an incrementing list. Fixes segfaults when, for example, using the valid API call: av_color_primaries_from_name("jecdec-p22"); Signed-off-by: Derek Buitenhuis --- libavutil/pixdesc.c | 35 ++++++++++++++++++++++++++++++----- 1 file changed, 30 insertions(+), 5 deletions(-) diff --git a/libavutil/pixdesc.c b/libavutil/pixdesc.c index ff5c20d50e..f849222aa3 100644 --- a/libavutil/pixdesc.c +++ b/libavutil/pixdesc.c @@ -2718,7 +2718,12 @@ int av_color_range_from_name(const char *name) int i; for (i = 0; i < FF_ARRAY_ELEMS(color_range_names); i++) { - size_t len = strlen(color_range_names[i]); + size_t len; + + if (!color_range_names[i]) + continue; + + len = strlen(color_range_names[i]); if (!strncmp(color_range_names[i], name, len)) return i; } @@ -2737,7 +2742,12 @@ int av_color_primaries_from_name(const char *name) int i; for (i = 0; i < FF_ARRAY_ELEMS(color_primaries_names); i++) { - size_t len = strlen(color_primaries_names[i]); + size_t len; + + if (!color_primaries_names[i]) + continue; + + len = strlen(color_primaries_names[i]); if (!strncmp(color_primaries_names[i], name, len)) return i; } @@ -2756,7 +2766,12 @@ int av_color_transfer_from_name(const char *name) int i; for (i = 0; i < FF_ARRAY_ELEMS(color_transfer_names); i++) { - size_t len = strlen(color_transfer_names[i]); + size_t len; + + if (!color_transfer_names[i]) + continue; + + len = strlen(color_transfer_names[i]); if (!strncmp(color_transfer_names[i], name, len)) return i; } @@ -2775,7 +2790,12 @@ int av_color_space_from_name(const char *name) int i; for (i = 0; i < FF_ARRAY_ELEMS(color_space_names); i++) { - size_t len = strlen(color_space_names[i]); + size_t len; + + if (!color_space_names[i]) + continue; + + len = strlen(color_space_names[i]); if (!strncmp(color_space_names[i], name, len)) return i; } @@ -2794,7 +2814,12 @@ int av_chroma_location_from_name(const char *name) int i; for (i = 0; i < FF_ARRAY_ELEMS(chroma_location_names); i++) { - size_t len = strlen(chroma_location_names[i]); + size_t len; + + if (!chroma_location_names[i]) + continue; + + len = strlen(chroma_location_names[i]); if (!strncmp(chroma_location_names[i], name, len)) return i; }