From patchwork Wed Aug 7 03:48:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Osamu Watanabe X-Patchwork-Id: 50920 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a59:d7b2:0:b0:489:2eb3:e4c4 with SMTP id dc18csp129189vqb; Tue, 6 Aug 2024 20:49:08 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCVi4pTzrGNRNzCF/SwQkAfoBl8wItb8OE86QVO9pvlBW0DcRcILfZxDdFm+jntFyeL8QKz1ugeGnXvIHeAYyq3cngyhmdtcofSqyw== X-Google-Smtp-Source: AGHT+IGq2MPQIvZto8d2Dcx/kjAgHiywYzJGbTJ5lDoazghlzlhM8BOs9+NB8umH4DREnD4N+igo X-Received: by 2002:a05:6512:3f0d:b0:52c:9421:2739 with SMTP id 2adb3069b0e04-530bb366816mr10413816e87.9.1723002548313; Tue, 06 Aug 2024 20:49:08 -0700 (PDT) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id a640c23a62f3a-a7dc9c169a4si636168066b.236.2024.08.06.20.49.07; Tue, 06 Aug 2024 20:49:08 -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=@takushoku.onmicrosoft.com header.s=selector2-takushoku-onmicrosoft-com header.b="px+h/bGG"; arc=fail (body hash mismatch); 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 Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id E43A168DAD2; Wed, 7 Aug 2024 06:49:03 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from OS0P286CU011.outbound.protection.outlook.com (mail-japanwestazon11020077.outbound.protection.outlook.com [52.101.228.77]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id A570968D9C9 for ; Wed, 7 Aug 2024 06:48:55 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=P00TQN8fESdhSUUcC6abRbI2c9wmmrib20BuqxyngSEkSr0cm0ybQJCD3WTxZOX3ABA3l5FhkKeF4g/dXmiXHrf5KCpmeY7IRoih1EEv5xF++qPy/3ySDTv8CnyinFo/7nkTqfYG0wWId0Qev8kNIT0Q7aSDFGfDDG6MYdE1cDYNMEyB2ZH49SyUkcoIQLuNsxsVVUjs5UaE9pGyip37FxxckEFo1dswjoBqIRf5d4QtX2WlaIrEzGa9TYF9vb59aFGmmr4G4f4eSwOSQjg5Y7tBkP9KypEWcSqTqYgu38J9ZYzOixpoUr+Jcj5FT69H18JfN8Ih93L1UBlkqJt74A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=NT0Z5c3UVQHpuTDQzAT9yMGDRrgWTYK5400zKlNJIVU=; b=P1137uCywCCvPHI5PJ3QBvXOFOdnB3o3tVRwnydMSdVlHwZ3OhcwcFC6wpJdxagsE5dVAQ0/NDeYTf9/YLp6peoBDAEvc52Ookk/rvcqNBFYypzjBvGyHMGKxksELWOUGJ05pEMyErqui/Xvvj7ONeuWmYtxTgjf7J9gUo9gyUQG4QgP4PtRXjNudf3AJ1PX8WySDvDvyOPtC2WkUTPG1YMUlUB222g3QJQDi7HYmsNwVtek50NGPRPVXYwxHE4Ja80yKBcvL8jCBawzBcum0203xyx+zdx22OTPgb/nHM0inSfS7GuFdVuoRRy3C/OOfisqSPs4kGaaRyE2Grbjkw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=es.takushoku-u.ac.jp; dmarc=pass action=none header.from=es.takushoku-u.ac.jp; dkim=pass header.d=es.takushoku-u.ac.jp; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=takushoku.onmicrosoft.com; s=selector2-takushoku-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=NT0Z5c3UVQHpuTDQzAT9yMGDRrgWTYK5400zKlNJIVU=; b=px+h/bGGj6JZ3S0gtpttWoh5dbLt+IppjOkjvB224XvE1TMFB4H5ndupZvCUIFoE/gctm1LbdEvhRSrKDJr6nnevx9RjyQS2gAGVynaNCiPHHrb2vwA9qD445O/Fkkb7Y65plXd+dIgw83DPSAFHmVfYpKkUGOGmgbNrVJgCZwQ= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=es.takushoku-u.ac.jp; Received: from TYCPR01MB6016.jpnprd01.prod.outlook.com (2603:1096:400:4c::12) by OSCPR01MB12849.jpnprd01.prod.outlook.com (2603:1096:604:337::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7849.13; Wed, 7 Aug 2024 03:48:50 +0000 Received: from TYCPR01MB6016.jpnprd01.prod.outlook.com ([fe80::32fe:be82:2878:fc7c]) by TYCPR01MB6016.jpnprd01.prod.outlook.com ([fe80::32fe:be82:2878:fc7c%7]) with mapi id 15.20.7849.008; Wed, 7 Aug 2024 03:48:50 +0000 From: Osamu Watanabe To: ffmpeg-devel@ffmpeg.org Date: Wed, 7 Aug 2024 12:48:43 +0900 Message-Id: <20240807034845.363526-1-owatanab@es.takushoku-u.ac.jp> X-Mailer: git-send-email 2.34.1 X-ClientProxiedBy: TY2PR02CA0010.apcprd02.prod.outlook.com (2603:1096:404:56::22) To TYCPR01MB6016.jpnprd01.prod.outlook.com (2603:1096:400:4c::12) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: TYCPR01MB6016:EE_|OSCPR01MB12849:EE_ X-MS-Office365-Filtering-Correlation-Id: 4aa6ecc2-6aa1-4a2d-6476-08dcb693d893 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|366016|41320700013|1800799024|376014|52116014|38350700014; X-Microsoft-Antispam-Message-Info: D57C3NFlCIuJ2Z2LsRCScp7YVJps3inbWFgHMdcqvnYJAljCuaBhyqx3VrnYTrf7DwJxgC9gkyjF3jwtGVMvKRl+faN81P43nq1jVnZ2Jch06CwXfLfTag8OOyzWB5Z34smTaHsd2dwBeBvAPmanoEMtkhNZ9ZJ+qYSV4J/x3ymdQQDSwFum1OcqJLmHtYfmltX6o4KyRiiDs7S+rKDfnlss5xWaQuzZO3ZAyk06ttiMbJmxpnQg8RMw9sOnlexAuz/4px52Bf3CKwF8HKM9PhWe1IGCjoml8Rlz5i9DMZe8lkO6kN4t8IGchNaE4w1xgzkv9kaZXS/1ltlB6hU3GEbh3RZbv+1OYvMbDn62uIVy5prM8DOmE94uAJJAn+MMl+tX7wGJZj+7Brc+4tYLoINcx6thnArLML6h1YYnRZJDi7Huf6q5u1ImD3h/AvEBXlid/5dFoCjHwJHg3UT4WlysnAcqAV9+8yOWF0rkTAf0PobjG+8MTmC7H469K+/iFBiaDCtRYkCpVggUgNxTWcY6M2xrga1Ep4KEBLYZrVdDRolvI1BrRdgRD7pnBcJ0yf7R0Bm6J57+pGdfRQxaU7n7GsYhtQMh+S3JwRLssRYlhRcRL5Eif98XTasFpZwheANy8UGbt9D9zT9kOizOKPhVWgRjXk5lqr/DUuKfkVBAr4fPwjps8d/gPTG8/TUrHg2KcRN9hAYntUXCSRh+fLTEiBUXMOZjiEbzkUa//hf1nakTM2G38ksvcVzJCPuFSeN6XB38LVEGITYFpFDMLH6tzmjRdxmWN3NQCK6ZwnCuVIPufyVbNtut776OlYrqQ8eIzB4o+ezC5vmCTnkE5PEO+ozRWMoDGI29RpFcEGk2pc+8pKP9OoO2eNy3iZC/rmZuabUh6m3e1nuIkRvD2UR4oZPOKOpgTa2iTBt3NvBHQ1mGDjct+8L1JkbdO7aItF98DFGokIMTAqlh+4E27dL8E+fd3/6Hn/t/FKwt0aKDYJsfcEwwxrOXLNPyGHEquXip+L0pwlThq+2F0VTD2LPMA4HtYvVawb/2Qyv36VkLDgZ8gSGU+HgSJxWwLzdUu0b3ADPoK3QYuICGVLQspVX3drKUlC9isAsIDWxoRQRj+lznTXSuRNGToWxo9CAdkN6V8sAF5hdgXfEiCKakFLEL0PsRrxzP8OED9nfx1dO3gQoKMcTLFxVRF2fpAV0TJ55eVW6Px02EMwOoYXCB1TMq6MveYjywbrUorWpN0IA7SKgzuTZxCL5UUVZ9A8ea8SrLKz/X9t7pLy0NhIA0zm+NP/m84+44skcCXbihguY+Mv+6JcBzvWW+xcSiS9WuOAeGE9EedIINgMwV231vZEADgS6D4snmKlAmExhsPU47XlFnXq1h/Uwf7d/bf/RpmqC4PZf6jjx+sn1HsQkV3Q== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:TYCPR01MB6016.jpnprd01.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230040)(366016)(41320700013)(1800799024)(376014)(52116014)(38350700014); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: eKSSX5IMfJWxKJN5+a7Rlnl8xqcjn6QHbIK412isD51NFK+ykbwMsOnzNt505B+Px2FkTs5NKQ2PGLGioRWnRI48XADFxJWgEXQIKN2AtX+MFlVczcCx/Sd8kJuF5ftsr9o3fCyFEf5s0JUnuV+3N5QcdMnTHAbnbZEklqZ8J5XERGoTqwPpJAwNIN6TTqg/KqZSxgpyjX6qWbekYccYPkl3mwUA/vBMK8cFhudb07YvSDXiPL9w5GlPq+zlMimFf+Bc0fEtslZKbGigJ+BFVBHl/AbtYJNIaW3wjvQe23Ru0zvcfSPooPSj2Ryy15iDvCkSaio8no83C4aCNO+sg1Y9nWc7IZwJO6FWqztrQE3/SAJMmJCQV5ULdayPe4w0oAWebb7xEUDPsyIt4GT8kCcoUV1kL3pubrYWc1wlzNeB7X0Nvf43LXDOT8eiAdP3OXykgzKh9sVJnmY4QVEuvAelIjOUNr6dvf8UNMQg5GE2/+q/pcFx1J+vuWHu7LHsKbRz+yVL4MNt85PDK8l956/C0SePD5F1G4JLtSqBPFEW72ctO2XjP9Wnru2tBcrTkBWztNgsHHjEdDOzSGdK9xQzhK3/j6wn/15M+ScCtEu7Srg/5m9GLGB6q7Un8NDYaaAYU1RzauzM+YiGLjSXbvS0U2C8q4WOk8tvyUuWc701lKwTFcjDDqzky3vhxWf4Cgq34nZPqTxuBBFLSyNnVYEX8L13sBirlXz5U1I4q5SaIJPK4aelU3WyK3OD3UMS/yBPjNSOBguJJ/gcTux8vAwh14PBRNqUoN3KO7ywDDdZ805rz/7MSIkcDElHPmDmbOP4qJx8E4DqsDb/Yiukdo3dKOHFaJOk1sN/zUSK1xzmIL6bqCi4TZ6a85n13VQG7LSW+RqEQQrHeBxeRut6hNyxjcsWYo4BAhNe+2VcXn0nuSRU02qfxMEWTMl/6oU5A4jeAFscOdnjyxLp5QrBqGSNfkVVC8xgW5UvKGzeRJaJeajIndhKA57g/68IDxdKERcB5FuPClPcc6pPCisZalKHWe9DDIj0O/5Kn/TsrusdYySnAT5pKMFPXve7FFOiq4Mqov0HtfoRtnIncSFr/77yHrLWjIO0dFaVHCtZppDTaCoYpzW2myM3a8IFuLEfkQpgMSvRcJGL3ZtA1afMD5o0UeAJ6oHXRSYNG8z8kG5xVqAROqDgZtcczCAK1rA+Hi9X9COjPljoA4luwq2p6w4eizPVvYzT0VHlXbQvhP2J3nMemhp9uNUv9jyRwU+UpJ9r85XkcbQRZ5V/uJaZ8sjxJEktmSlnmWavYp2R2Lq5zoQ+QvVe/tKAW857fgX6Yl8YD3qqV3NoVrrw1KefgQZORpUXkk/J54A3uub+q/jKdis/7rmaGQKBNDyN2TpCiGt/shhW3E310F8ZlT1idKAMNDVDJBFzUqz+FZc1FZ2vr31UaxAskVZOkqsAW5yoeWea2fd22tmxCetFCBjaCOloHRgjmOkzxozTvJ2M/Ec/IT3P/shGH1IsvjvzJrzzJ+Zj1PkdZWmgnVDa00wk54rmVwWmpkEeDo+IuvS5HQ8ECnU5X7QajkcL6Mt8Age0YpUlpH8i6nnO3aCWKfe+Ig== X-OriginatorOrg: es.takushoku-u.ac.jp X-MS-Exchange-CrossTenant-Network-Message-Id: 4aa6ecc2-6aa1-4a2d-6476-08dcb693d893 X-MS-Exchange-CrossTenant-AuthSource: TYCPR01MB6016.jpnprd01.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Aug 2024 03:48:50.0757 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 853333e5-13b1-4738-ae04-bfb589cf2665 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: cvgBkQYbZJz/6NklpoLFPkiwYkA4AWoSL2omYZer2qHRZBWn/mL+2baZZrMXdEdr5b3zr+mcMs5mWsnROyQj+RySDSgbu1TyRAwaAyHxlBQ= X-MS-Exchange-Transport-CrossTenantHeadersStamped: OSCPR01MB12849 Subject: [FFmpeg-devel] [PATCH v8 1/3] avcodec/jpeg2000dec: Add support for CAP and CPF markers X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 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 Cc: Osamu Watanabe , pal@sandflow.com Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: DMcj85u11/ZT This commit adds support for CAP and CPF markers. Decoding will exit when encountering Ilegal input codestreams. Signed-off-by: Osamu Watanabe --- libavcodec/jpeg2000.h | 8 +++ libavcodec/jpeg2000dec.c | 134 ++++++++++++++++++++++++++++++++++++++- libavcodec/jpeg2000dec.h | 7 ++ 3 files changed, 148 insertions(+), 1 deletion(-) diff --git a/libavcodec/jpeg2000.h b/libavcodec/jpeg2000.h index d004c08f10..4bdc38df7c 100644 --- a/libavcodec/jpeg2000.h +++ b/libavcodec/jpeg2000.h @@ -37,12 +37,14 @@ enum Jpeg2000Markers { JPEG2000_SOC = 0xff4f, // start of codestream + JPEG2000_CAP = 0xff50, // extended capabilities JPEG2000_SIZ = 0xff51, // image and tile size JPEG2000_COD, // coding style default JPEG2000_COC, // coding style component JPEG2000_TLM = 0xff55, // tile-part length, main header JPEG2000_PLM = 0xff57, // packet length, main header JPEG2000_PLT, // packet length, tile-part header + JPEG2000_CPF, // corresponding profile JPEG2000_QCD = 0xff5c, // quantization default JPEG2000_QCC, // quantization component JPEG2000_RGN, // region of interest @@ -58,6 +60,12 @@ enum Jpeg2000Markers { JPEG2000_EOC = 0xffd9, // end of codestream }; +enum JPEG2000_Ccap15_b14_15_params { + HTJ2K_HTONLY = 0, // HTONLY, bit 14 and 15 are 0 + HTJ2K_HTDECLARED, // HTDECLARED, bit 14 = 1 and bit 15 = 0 + HTJ2K_MIXED = 3, // MIXED, bit 14 and 15 are 1 +}; + #define JPEG2000_SOP_FIXED_BYTES 0xFF910004 #define JPEG2000_SOP_BYTE_LENGTH 6 diff --git a/libavcodec/jpeg2000dec.c b/libavcodec/jpeg2000dec.c index 091931b1ff..62faa8d9f5 100644 --- a/libavcodec/jpeg2000dec.c +++ b/libavcodec/jpeg2000dec.c @@ -408,6 +408,73 @@ static int get_siz(Jpeg2000DecoderContext *s) s->avctx->bits_per_raw_sample = s->precision; return 0; } +/* get extended capabilities (CAP) marker segment */ +static int get_cap(Jpeg2000DecoderContext *s, Jpeg2000CodingStyle *c) +{ + uint32_t Pcap; + uint16_t Ccap_i[32] = { 0 }; + uint16_t Ccap_15; + uint8_t P; + + if (bytestream2_get_bytes_left(&s->g) < 6) { + av_log(s->avctx, AV_LOG_ERROR, "Underflow while parsing the CAP marker\n"); + return AVERROR_INVALIDDATA; + } + + Pcap = bytestream2_get_be32u(&s->g); + s->isHT = (Pcap >> (31 - (15 - 1))) & 1; + for (int i = 0; i < 32; i++) { + if ((Pcap >> (31 - i)) & 1) + Ccap_i[i] = bytestream2_get_be16u(&s->g); + } + Ccap_15 = Ccap_i[14]; + if (s->isHT == 1) { + av_log(s->avctx, AV_LOG_INFO, "This codestream uses the HT block coder.\n"); + // Bits 14-15 + switch ((Ccap_15 >> 14) & 0x3) { + case 0x3: + s->Ccap15_b14_15 = HTJ2K_MIXED; + break; + case 0x1: + s->Ccap15_b14_15 = HTJ2K_HTDECLARED; + break; + case 0x0: + s->Ccap15_b14_15 = HTJ2K_HTONLY; + break; + default: + av_log(s->avctx, AV_LOG_ERROR, "Unknown CCap value.\n"); + return AVERROR(EINVAL); + break; + } + // Bit 13 + if ((Ccap_15 >> 13) & 1) { + av_log(s->avctx, AV_LOG_ERROR, "MULTIHT set is not supported.\n"); + return AVERROR_PATCHWELCOME; + } + // Bit 12 + s->Ccap15_b12 = (Ccap_15 >> 12) & 1; + // Bit 11 + s->Ccap15_b11 = (Ccap_15 >> 11) & 1; + // Bit 5 + s->Ccap15_b05 = (Ccap_15 >> 5) & 1; + // Bit 0-4 + P = Ccap_15 & 0x1F; + if (!P) + s->HT_B = 8; + else if (P < 20) + s->HT_B = P + 8; + else if (P < 31) + s->HT_B = 4 * (P - 19) + 27; + else + s->HT_B = 74; + + if (s->HT_B > 31) { + av_log(s->avctx, AV_LOG_ERROR, "Codestream exceeds available precision (B > 31).\n"); + return AVERROR_PATCHWELCOME; + } + } + return 0; +} /* get common part for COD and COC segments */ static int get_cox(Jpeg2000DecoderContext *s, Jpeg2000CodingStyle *c) @@ -802,6 +869,15 @@ static int read_crg(Jpeg2000DecoderContext *s, int n) bytestream2_skip(&s->g, n - 2); return 0; } + +static int read_cpf(Jpeg2000DecoderContext *s, int n) +{ + if (bytestream2_get_bytes_left(&s->g) < (n - 2)) + return AVERROR_INVALIDDATA; + bytestream2_skip(&s->g, n - 2); + return 0; +} + /* Tile-part lengths: see ISO 15444-1:2002, section A.7.1 * Used to know the number of tile parts and lengths. * There may be multiple TLMs in the header. @@ -965,6 +1041,14 @@ static int init_tile(Jpeg2000DecoderContext *s, int tileno) comp->roi_shift = s->roi_shift[compno]; if (!codsty->init) return AVERROR_INVALIDDATA; + if (s->isHT && (!s->Ccap15_b05) && (!codsty->transform)) { + av_log(s->avctx, AV_LOG_ERROR, "Transformation = 0 (lossy DWT) is found in HTREV HT set\n"); + return AVERROR_INVALIDDATA; + } + if (s->isHT && s->Ccap15_b14_15 != (codsty->cblk_style >> 6) && s->Ccap15_b14_15 != HTJ2K_HTONLY) { + av_log(s->avctx, AV_LOG_ERROR, "SPcod/SPcoc value does not match bit 14-15 values of Ccap15\n"); + return AVERROR_INVALIDDATA; + } if (ret = ff_jpeg2000_init_component(comp, codsty, qntsty, s->cbps[compno], s->cdx[compno], s->cdy[compno], s->avctx)) @@ -2187,22 +2271,63 @@ static int jpeg2000_read_main_headers(Jpeg2000DecoderContext *s) if (!s->tile) s->numXtiles = s->numYtiles = 0; break; + case JPEG2000_CAP: + if (!s->ncomponents) { + av_log(s->avctx, AV_LOG_ERROR, "CAP marker segment shall come after SIZ\n"); + return AVERROR_INVALIDDATA; + } + ret = get_cap(s, codsty); + break; case JPEG2000_COC: + if (s->in_tile_headers == 1 && s->isHT && (!s->Ccap15_b11)) { + av_log(s->avctx, AV_LOG_ERROR, + "COC marker found in a tile header but the codestream belongs to the HOMOGENEOUS set\n"); + return AVERROR_INVALIDDATA; + } ret = get_coc(s, codsty, properties); break; case JPEG2000_COD: + if (s->in_tile_headers == 1 && s->isHT && (!s->Ccap15_b11)) { + av_log(s->avctx, AV_LOG_ERROR, + "COD marker found in a tile header but the codestream belongs to the HOMOGENEOUS set\n"); + return AVERROR_INVALIDDATA; + } ret = get_cod(s, codsty, properties); break; case JPEG2000_RGN: + if (s->in_tile_headers == 1 && s->isHT && (!s->Ccap15_b11)) { + av_log(s->avctx, AV_LOG_ERROR, + "RGN marker found in a tile header but the codestream belongs to the HOMOGENEOUS set\n"); + return AVERROR_INVALIDDATA; + } ret = get_rgn(s, len); + if ((!s->Ccap15_b12) && s->isHT) { + av_log(s->avctx, AV_LOG_ERROR, "RGN marker found but the codestream belongs to the RGNFREE set\n"); + return AVERROR_INVALIDDATA; + } break; case JPEG2000_QCC: + if (s->in_tile_headers == 1 && s->isHT && (!s->Ccap15_b11)) { + av_log(s->avctx, AV_LOG_ERROR, + "QCC marker found in a tile header but the codestream belongs to the HOMOGENEOUS set\n"); + return AVERROR_INVALIDDATA; + } ret = get_qcc(s, len, qntsty, properties); break; case JPEG2000_QCD: + if (s->in_tile_headers == 1 && s->isHT && (!s->Ccap15_b11)) { + av_log(s->avctx, AV_LOG_ERROR, + "QCD marker found in a tile header but the codestream belongs to the HOMOGENEOUS set\n"); + return AVERROR_INVALIDDATA; + } ret = get_qcd(s, len, qntsty, properties); break; case JPEG2000_POC: + if (s->in_tile_headers == 1 && s->isHT && (!s->Ccap15_b11)) { + av_log(s->avctx, AV_LOG_ERROR, + "POC marker found in a tile header but the codestream belongs to the HOMOGENEOUS set\n"); + return AVERROR_INVALIDDATA; + } ret = get_poc(s, len, poc); break; case JPEG2000_SOT: @@ -2252,9 +2377,16 @@ static int jpeg2000_read_main_headers(Jpeg2000DecoderContext *s) "Cannot have both PPT and PPM marker.\n"); return AVERROR_INVALIDDATA; } - + if ((!s->Ccap15_b11) && s->isHT) { + av_log(s->avctx, AV_LOG_ERROR, "PPT marker found but the codestream belongs to the HOMOGENEOUS set\n"); + return AVERROR_INVALIDDATA; + } ret = get_ppt(s, len); break; + case JPEG2000_CPF: + // Corresponding profile marker + ret = read_cpf(s, len); + break; default: av_log(s->avctx, AV_LOG_ERROR, "unsupported marker 0x%.4"PRIX16" at pos 0x%X\n", diff --git a/libavcodec/jpeg2000dec.h b/libavcodec/jpeg2000dec.h index d0ca6e7a79..166cce9eba 100644 --- a/libavcodec/jpeg2000dec.h +++ b/libavcodec/jpeg2000dec.h @@ -112,6 +112,13 @@ typedef struct Jpeg2000DecoderContext { Jpeg2000Tile *tile; Jpeg2000DSPContext dsp; + uint8_t isHT; // HTJ2K? + uint8_t Ccap15_b14_15; // HTONLY(= 0) or HTDECLARED(= 1) or MIXED(= 3) ? + uint8_t Ccap15_b12; // RGNFREE(= 0) or RGN(= 1)? + uint8_t Ccap15_b11; // HOMOGENEOUS(= 0) or HETEROGENEOUS(= 1) ? + uint8_t Ccap15_b05; // HTREV(= 0) or HTIRV(= 1) ? + uint8_t HT_B; // MAGB value + /*options parameters*/ int reduction_factor; } Jpeg2000DecoderContext;