From patchwork Thu Aug 1 01:52:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: WATANABE Osamu X-Patchwork-Id: 50841 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a59:12d6:0:b0:489:2eb3:e4c4 with SMTP id 205csp849457vqs; Wed, 31 Jul 2024 18:53:09 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCVzOIRsOmOscetM2yLhDtok1TAsWNJi3pMutHKlW59WNTMm+jQeL97G3Tgozy3wWc479TYdV1gZl/RkPitC1Z0pYWWID+lSfdUBfQ== X-Google-Smtp-Source: AGHT+IG0QNV3CDJUPYXrpHo8Ch13pCLx2z5Kdu20YMmZ85P0IT5fwH2ScdpWzInyhAI5IQlaYguu X-Received: by 2002:a05:6512:114b:b0:52c:dfa0:dca0 with SMTP id 2adb3069b0e04-530b61ed447mr433812e87.43.1722477188853; Wed, 31 Jul 2024 18:53: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 4fb4d7f45d1cf-5ac6557a91esi9704805a12.374.2024.07.31.18.53.08; Wed, 31 Jul 2024 18:53: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=QQkmDSmK; 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 554B768CA5B; Thu, 1 Aug 2024 04:53:05 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from TY3P286CU002.outbound.protection.outlook.com (mail-japaneastazon11020123.outbound.protection.outlook.com [52.101.229.123]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 1329068CA5B for ; Thu, 1 Aug 2024 04:52:58 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=d5vgQ4k3cJYD/SlExnfUt8rMrtZLMQwQ2Z7XmrHE8wx/sx7u6TNOtxZnroRLhEoTlA7oni123GITsUSrbVyK5rj1eWHg/mG2nL9AsrHnTyE+Za10MMEUSSoXIPqM9yJWL6hksn5Hox9CZkH1jsKP/rxoeyid5iL7kIKa8qTpaskwtnOTtEGuRfYi7b6JPimAmyT8j10wNCw92ipn8x9UhOT3ZpevMgoE0fpLkUfkzwiDBMVBp4qt/PCwQ3SV9IQlOEv02HXZFxZoUH0ilHt3qLrGo0CWYtivQSBIoiiEHAJFUdQ2JwzLjPJBu5dDLIeieAvIGoi/G78iEbG84F14Jw== 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=n1zF21T41LtonzNw59TV6+C3NEkTkacFGA6AR/sUgVE=; b=QDBtvMF+hTEf6tat5htk9Cfsb2leHC0fWl0N9GiASviISGiOl9vD40S0kFj1BFh9UrlvJ7ToTwlfBbILWDxwia/S6y+nVfuOmuwb5IotVHPArpJ1stY1GPLdoBFq4F7j3h+uUFjdAMo7bTCDof3krbQfE148bVHF0QR/NVqlSZNwZO3fOwZ0JAyzVecEILAzOndbayAEj8HWI4rn7+/nuTvPu/HlEQEba3SucJP9ixpW8wNy6Mr5ZLBd2rv2I0N3V3WXKQBg9eXpn8x2y2YsnE1fMxT4Lwl5veb6HBEIaBjMAIPO83l5wBNg8wHgetp0TFavZAHWH1U+71gSC4oGvA== 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=n1zF21T41LtonzNw59TV6+C3NEkTkacFGA6AR/sUgVE=; b=QQkmDSmKlUF4oNDmpL1I3mNCm2JpUmj9iEuPAnOHfhSbn6YteOvauc5YrHIn+sWFQG18yw5cic86bAPMT2fe7eIzlQOzRCXKlT8weP6MQbQ2I6e3hepz6SzlTraSa1OMf3w7Wgwn9TPoFQuQCrWN+bZZlQBrGj5l7KlFAaaGTkQ= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=es.takushoku-u.ac.jp; Received: from OS0PR01MB6001.jpnprd01.prod.outlook.com (2603:1096:604:b7::12) by TYCPR01MB7011.jpnprd01.prod.outlook.com (2603:1096:400:be::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7828.21; Thu, 1 Aug 2024 01:52:53 +0000 Received: from OS0PR01MB6001.jpnprd01.prod.outlook.com ([fe80::181c:c1f4:9b58:f6cc]) by OS0PR01MB6001.jpnprd01.prod.outlook.com ([fe80::181c:c1f4:9b58:f6cc%3]) with mapi id 15.20.7828.021; Thu, 1 Aug 2024 01:52:53 +0000 From: Osamu Watanabe To: ffmpeg-devel@ffmpeg.org Date: Thu, 1 Aug 2024 10:52:33 +0900 Message-Id: <20240801015235.181022-1-owatanab@es.takushoku-u.ac.jp> X-Mailer: git-send-email 2.34.1 X-ClientProxiedBy: TY2PR01CA0019.jpnprd01.prod.outlook.com (2603:1096:404:a::31) To OS0PR01MB6001.jpnprd01.prod.outlook.com (2603:1096:604:b7::12) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: OS0PR01MB6001:EE_|TYCPR01MB7011:EE_ X-MS-Office365-Filtering-Correlation-Id: 9c70ab10-798a-4388-0e40-08dcb1cca790 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|41320700013|1800799024|366016|52116014|376014|38350700014; X-Microsoft-Antispam-Message-Info: NFrF3HI9Y+lennrK6ivDPPa4+7y1Q9/JXaxhyfyse5PNAAZsuLqVeoS4MFQqO8/0H/GFsxsU+z5iDwgorm2mavBrsRuhM/nmgydGeERXPo7HHtBCEyB6axAb4681mCy/cOFSRDtybp1ytyBkdurn31wIcQgZgHHuejW1FGcSHfjZ7V/4q+3RBAkcukKNe3zz8HNrz6Z4F9KxlGxahAF9Hie473rP4ZikR/i8n6DmiXVffe+MWHJJEeNWz18W6RHCgP2W5IimxouZefrOyPNeXF2SvWZw9dBaFUp9VHBi4KuWWsFHazdGNwdWKU6tugTyryVegFwHRn1UKlYFPd8yttcpqw/YJtNHhmDdScn9Ykvgysd/kx1OHRKyL27sOO3b+rgtbu4JHlAqcCpym0n3QHxyhRNDgNTodKpJKhGHvZseI8JoCh4OF09Hp0hyjmDq5YFE2DlzPpFO9niGzFZvcKCjFfmDU/8SSi9Nnr2vN1gqCCtjeC3BWHZKaN0+zaVM8OiBSIixvYoaMUc1RkUymhQzhKNamrkbHGv1yf2jDjM7tVHZ/6eVfRtYNOq3xwzYZzUMXjltY+xJd7jtLbhwJ4j485IxewtVv4/wQoRXGadin1MuHk2r4P7k94iCkGx2QwGyJTsm9Izkys3oW1GdBZgPI7URH59S6ivuDZDcysoabvoMtbfj1KSE+dXJhjDhjtZA4vvXUa4EwS+j0mfEA+ANNdy3o4BUF+1vNr+NPKGArqcpJm0kd0c6po94Rb+6lv0v0hJPUrYdqEg3sWK02x2zQOZ2feZ6jwUc0mk9F93xkrpJaqq5/f2t2meUmaMOcaZglVJHxud+OBaTY0LdNzerM3EpEVeGhGBU6SEvZ/7HezIz8TocgSYVibugxMe6QKJwQXl4hMg/1ToPPoSCzIiY5OYv90ZDZV+/4gqmBsji943VSdA0VrlfvSYSRMZBh9FkpdcJK+sK0jwzuaJCPyF1oaTjqZPAlOBSuTpr8HTii35376PCeNMjFnbqGCgudeYJBuFFOMOCtPqq6j/Rr6ZwC6OIh49KWZ0/uMWK1+f58vjgSNAw2riZZVz1UWoKTXwT6LGXhwV1WcdRvlON1zDsv3lK/N8wyQXX7OwqvBOtYR87XIk91jdyQgW7IU/EfPzpUxHIXjPCpulSZkRiDAq+8FsdwyrrRYTwFeEBvEIjjilUW7C7ll/IPIv5VSZuL7VQUTYM3Zlqvi98p59Z5trhNeLiIc9/yX26oSNm4IkabDvMellLSXrKp5lxDvw0Y0YFI80SA0k5g/f8+a/2z2LY4q/VPorv+r6UiNei3KXtLclWxKPFyGd76VbyDtuzBFI6BXo1H/AnLawrbT9+dFrFSJO7DFqLixint+FcVVm+rHNdEPHF7VyltgkLnSVLV7xOPsSB74aDUFN/108C8w== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:OS0PR01MB6001.jpnprd01.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230040)(41320700013)(1800799024)(366016)(52116014)(376014)(38350700014); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: R6nE2bElDW97hBK8Ug7lXmfUQO0bzXEc2TA9hcODwFt6lrpHvPUBrkA5wKv4RiQ8pPHlXssI24TbPl2DInB04kDljNIfzXDmCEmQfNRF68k8+e0rDQ684JH0PO+QcpZXSy3Mt0UC+SdYdYZ4zj0HeIXtmYfii7ZWv8sL4lkzTEFIdwXjH1aNPuF48H4r+sRhLzzKm45X98FsMbso7iCsdmdw88dCp+i7fYDFRj2l9f7YpiSgz1EvujCbWojReDqv4epeWd5Lp7kRGnXuf0iA+yhZnzMCUxChe8z66zV4GbzfbW1Y4eqKaX2yTeycMMQM/MfpFGZdksapDfum5iaZcKGIJilVrQZ0F7ZUYZ6vQcTS2XZ/jJpyV7B4agYov97CzFpMgjAF2x4oX6CurBH1Qp4mgVMmByOHWNw1YMUnLB2k36v5cRXxKk0eapRrnTDPF5X/xIDwDfPDX0rUNYe6nEUA9KISlmJ9X83QN/Rqbv3oAZ30sswrgnk6xHDZ5vh6SOUjiskgnQeSDap7mHK8E3AhhfSrBC/m9XWXN8wYJF2X8PghzVyztP/2G0/VWbtyKOZt4b1a7OjVTnAFikpD6Na7nIgbZh8+vakbwaygqWcPU2QnNxWyQ+BnyY7a017CECPlLxzjePUGBsHmCS4CQtiTSdkdAB4rfyfFENo3dr51htLMHmaO3wtzZlNIzXxlJrdTIw96OiRh+74VTxhrXwiuMsEgxtHWO6LdvI9qR9Ue+HQlj9hDyPTLEKcPZNK/GbRTJ5BZaijYVhPlBz+3hX0BbaBeEP0fVg5HCHptKSRCSCjsS60Otk4fgykXH2b7GbS51HqLQu7LAmi/bUcASDXZ8ya0XuKHyC8WaVEWkpOxWUp3IMyGYSwcJNxMEAzg9VpqE50n/us6rKMZgGyNjE/nstc2ljTSWSqBrzqmUhzt6U8sgFJzd3sIr/m9e27chvFSkDUJm3S64vKFestyccU/QjOxNLl+Un0x2CTxR7ZV3US6s9BYedhHp3whS6Q3V19ls2ZSy8L2yjbKKJH+aIcoIlyAcXYXG+gDcBHyjiVv1ndYTOfZAX821oUp/iI0DQimU578UdGYajSXn6kUgcbverFdsgg7ManHXAimog6iFu82JlXuOLe/C5sOVyi57/Wyyxil/dc59OaNhDFDW0fdbHcUKxwFvwbbFvMA8WmgiBHjWRhiKp2n50NCr/YT81zz/+AIc/2UxJaTbbo7iSNfMv1gOYxz6MlxpuYgqpVdOPlbOz7XHiI0YEDfZRr/2cYf3Rj1D5BBaFuNH9CdJHtooVJhHo9XrNaw0QcKjWarg5i0SM0/UUxskWNq/QI72m6HQ6Oex9WzPVGIDVoKqqSrVKIjK4p4RPzx9zl5z/sGpwLi0XduWHQfmaN24YR1WGcYF1CF4V/O7e7syv1F7TK83ZRfDTdE/fSenP1IK+YvLac7cpOqUWK4SeAuRpImnJXtBYy0CtNXm/Id2jQNshpshpRqtSLsF9zWxlUtMm+/hX6N4PW8/K2Bs0IW/vWeMN6cb5e6DnszIXZ6HwaSTn71hwKrM2dCK1h0FpGWBdRCjRtesR7AVUmuginiOJbl/UDpEphgsE93ifUa10MQQg== X-OriginatorOrg: es.takushoku-u.ac.jp X-MS-Exchange-CrossTenant-Network-Message-Id: 9c70ab10-798a-4388-0e40-08dcb1cca790 X-MS-Exchange-CrossTenant-AuthSource: OS0PR01MB6001.jpnprd01.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Aug 2024 01:52:53.3380 (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: 3POCvQmZ5aDmKzQfvQh/IsE6Pz/1P/MPyM9pQoH2G1Q5Xl4E5VBC763tgugjdX9H1qiIYTAheod3egrL/tDhbS6+Jq5WeKlLOJt60V4uHow= X-MS-Exchange-Transport-CrossTenantHeadersStamped: TYCPR01MB7011 Subject: [FFmpeg-devel] [PATCH v5 1/3] This commit adds support for CAP and CPF markers. Decoder will exit when encountering an illegal codestream. 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: LR8cMAVSSga9 Signed-off-by: Osamu Watanabe --- libavcodec/jpeg2000.h | 8 +++ libavcodec/jpeg2000dec.c | 128 ++++++++++++++++++++++++++++++++++++++- libavcodec/jpeg2000dec.h | 7 +++ 3 files changed, 142 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..a1f82389fa 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, "Insufficient space for CAP\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 is an HTJ2K codestream.\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_MAGB = 8; + else if (P < 20) + s->HT_MAGB = P + 8; + else if (P < 31) + s->HT_MAGB = 4 * (P - 19) + 27; + else + s->HT_MAGB = 74; + + if (s->HT_MAGB > 31) { + av_log(s->avctx, AV_LOG_ERROR, "Available internal precision is exceeded (MAGB> 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,57 @@ 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 is found in HOMOGENEOUS HT 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 is found in HOMOGENEOUS HT 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, "RGB marker is found in HOMOGENEOUS HT 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 is found in RGNFREE HT 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 is found in HOMOGENEOUS HT 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 is found in HOMOGENEOUS HT 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 is found in HOMOGENEOUS HT set\n"); + return AVERROR_INVALIDDATA; + } ret = get_poc(s, len, poc); break; case JPEG2000_SOT: @@ -2252,9 +2371,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 is found in HOMOGENEOUS HT 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..326a572722 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_MAGB; // MAGB value + /*options parameters*/ int reduction_factor; } Jpeg2000DecoderContext;