diff mbox

[FFmpeg-devel,2/2] Inserted check on codeblock size, added limits on codeblock size Modified according to Niedermayer suggestions

Message ID 1501856495-13594-1-git-send-email-francesco@bltitalia.com
State New
Headers show

Commit Message

francesco@bltitalia.com Aug. 4, 2017, 2:21 p.m. UTC
From: Francesco Cuzzocrea <francesco@bltitalia.com>

---
 libavcodec/j2kenc.c | 30 +++++++++++++++++-------------
 1 file changed, 17 insertions(+), 13 deletions(-)

Comments

Michael Niedermayer Aug. 4, 2017, 11:02 p.m. UTC | #1
On Fri, Aug 04, 2017 at 04:21:35PM +0200, francesco@bltitalia.com wrote:
> From: Francesco Cuzzocrea <francesco@bltitalia.com>
> 
> ---
>  libavcodec/j2kenc.c | 30 +++++++++++++++++-------------
>  1 file changed, 17 insertions(+), 13 deletions(-)

patches should be against git master not on top of the previous patches
revission


[...]
diff mbox

Patch

diff --git a/libavcodec/j2kenc.c b/libavcodec/j2kenc.c
index 1bd4fbd..20dda87 100644
--- a/libavcodec/j2kenc.c
+++ b/libavcodec/j2kenc.c
@@ -1121,8 +1121,6 @@  FF_ENABLE_DEPRECATION_WARNINGS
     memset(codsty->log2_prec_heights, 15, sizeof(codsty->log2_prec_heights));
     codsty->nreslevels2decode=
     codsty->nreslevels       = 7;
-    codsty->log2_cblk_width  = 4;
-    codsty->log2_cblk_height = 4;
     codsty->transform        = s->pred ? FF_DWT53 : FF_DWT97_INT;
 
     qntsty->nguardbits       = 1;
@@ -1131,6 +1129,13 @@  FF_ENABLE_DEPRECATION_WARNINGS
         (s->tile_height & (s->tile_height-1))) {
         av_log(avctx, AV_LOG_WARNING, "Tile dimension not a power of 2\n");
     }
+    i = codsty->log2_cblk_width + codsty->log2_cblk_height -4;
+    if ( i > 12 )
+    {
+      av_log(avctx, AV_LOG_ERROR, "Invalid values for codeblocks size\n");
+      return -1;
+    }
+
 
     if (codsty->transform == FF_DWT53)
         qntsty->quantsty = JPEG2000_QSTY_NONE;
@@ -1178,21 +1183,20 @@  static int j2kenc_destroy(AVCodecContext *avctx)
 // taken from the libopenjpeg wraper so it matches
 
 #define OFFSET(x) offsetof(Jpeg2000EncoderContext, x)
-#define OFFSET1(x) offsetof(Jpeg2000CodingStyle, x)
 
 
 #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
 static const AVOption options[] = {
-    { "format",           "Codec Format",       OFFSET(format),                               AV_OPT_TYPE_INT,   { .i64 = CODEC_JP2   }, CODEC_J2K, CODEC_JP2,   VE, "format"      },
-    { "j2k",               NULL,                0,                                            AV_OPT_TYPE_CONST, { .i64 = CODEC_J2K   }, 0,         0,           VE, "format"      },
-    { "jp2",               NULL,                0,                                            AV_OPT_TYPE_CONST, { .i64 = CODEC_JP2   }, 0,         0,           VE, "format"      },
-    { "tile_width",        "Tile Width",        OFFSET(tile_width),                           AV_OPT_TYPE_INT,   { .i64 = 256         }, 1,     1<<30,           VE, },
-    { "tile_height",       "Tile Height",       OFFSET(tile_height),                          AV_OPT_TYPE_INT,   { .i64 = 256         }, 1,     1<<30,           VE, },
-    { "pred",              "DWT Type",          OFFSET(pred),                                 AV_OPT_TYPE_INT,   { .i64 = 0           }, 0,         1,           VE, "pred"        },
-    { "dwt97int",          NULL,                0,                                            AV_OPT_TYPE_CONST, { .i64 = 0           }, INT_MIN, INT_MAX,       VE, "pred"        },
-    { "dwt53",             NULL,                0,                                            AV_OPT_TYPE_CONST, { .i64 = 0           }, INT_MIN, INT_MAX,       VE, "pred"        },
-    { "log2_cblk_width",   "Codeblock Width",   (OFFSET(codsty)+OFFSET1(log2_cblk_width)),    AV_OPT_TYPE_INT,   { .i64 = 4           }, 1,     1<<30,           VE, },
-    { "log2_cblk_height",  "Codeblock Height",  (OFFSET(codsty)+OFFSET1(log2_cblk_height)),   AV_OPT_TYPE_INT,   { .i64 = 4           }, 1,     1<<30,           VE, },
+    { "format",           "Codec Format",       OFFSET(format),                    AV_OPT_TYPE_INT,   { .i64 = CODEC_JP2   }, CODEC_J2K, CODEC_JP2,   VE, "format"      },
+    { "j2k",               NULL,                0,                                 AV_OPT_TYPE_CONST, { .i64 = CODEC_J2K   }, 0,         0,           VE, "format"      },
+    { "jp2",               NULL,                0,                                 AV_OPT_TYPE_CONST, { .i64 = CODEC_JP2   }, 0,         0,           VE, "format"      },
+    { "tile_width",        "Tile Width",        OFFSET(tile_width),                AV_OPT_TYPE_INT,   { .i64 = 256         }, 1,     1<<30,           VE, },
+    { "tile_height",       "Tile Height",       OFFSET(tile_height),               AV_OPT_TYPE_INT,   { .i64 = 256         }, 1,     1<<30,           VE, },
+    { "pred",              "DWT Type",          OFFSET(pred),                      AV_OPT_TYPE_INT,   { .i64 = 0           }, 0,         1,           VE, "pred"        },
+    { "dwt97int",          NULL,                0,                                 AV_OPT_TYPE_CONST, { .i64 = 0           }, INT_MIN, INT_MAX,       VE, "pred"        },
+    { "dwt53",             NULL,                0,                                 AV_OPT_TYPE_CONST, { .i64 = 0           }, INT_MIN, INT_MAX,       VE, "pred"        },
+    { "log2_cblk_width",   "Codeblock Width",   OFFSET(codsty.log2_cblk_width),    AV_OPT_TYPE_INT,   { .i64 = 4           }, 0,     1<<10,           VE, },
+    { "log2_cblk_height",  "Codeblock Height",  OFFSET(codsty.log2_cblk_height),   AV_OPT_TYPE_INT,   { .i64 = 4           }, 0,     1<<10,           VE, },
     { NULL }
 };