jpeg2000: Check code-block size

Signed-off-by: Luca Barbato <lu_zero@gentoo.org>
Signed-off-by: Nicolas Bertrand <nicoinattendu@gmail.com>
Signed-off-by: Luca Barbato <lu_zero@gentoo.org>
jpeg2000: Define the maximum decomposition levels

And define the resolution levels according.

Signed-off-by: Luca Barbato <lu_zero@gentoo.org>
jpeg2000: Clean up return paths and error messages

Signed-off-by: Luca Barbato <lu_zero@gentoo.org>
jpeg2000: Use bytestream2

Prevent a number of overreads.

Found-by: Mateusz "j00ru" Jurczyk and Gynvael Coldwind
Signed-off-by: Luca Barbato <lu_zero@gentoo.org>
jpeg2000: Check component number in get_coc() and get_qcc()

Avoid overreads.

Found-by: Mateusz "j00ru" Jurczyk and Gynvael Coldwind
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
Signed-off-by: Nicolas Bertrand <nicoinattendu@gmail.com>
Signed-off-by: Luca Barbato <lu_zero@gentoo.org>
jpeg2000: Correctly calculate sgnd

Signed-off-by: Luca Barbato <lu_zero@gentoo.org>
jpeg2000: Validate SOT parsing

Avoid some overreads.

Signed-off-by: Luca Barbato <lu_zero@gentoo.org>
jpeg2000: Validate SIZ parsing

Found-by: Mateusz "j00ru" Jurczyk and Gynvael Coldwind
Signed-off-by: Luca Barbato <lu_zero@gentoo.org>
jpeg2000: Validate block lengthinc

Currently we are using an array with a static data size.

Similar to a patch with the same purpose by Michael Niedermayer.

Found-by: Mateusz "j00ru" Jurczyk and Gynvael Coldwind

Signed-off-by: Luca Barbato <lu_zero@gentoo.org>
jpeg2000: Check zero bit-plane validity

Prevent integer overflows.

Signed-off-by: Luca Barbato <lu_zero@gentoo.org>
jpeg2000: check len before parsing header

Avoid overread.

Found-by: Mateusz "j00ru" Jurczyk and Gynvael Coldwind
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
Signed-off-by: Luca Barbato <lu_zero@gentoo.org>
jpeg2000: Drop unused and writeonly fields

Signed-off-by: Luca Barbato <lu_zero@gentoo.org>
jpeg2000: Check that we have enough components for MCT

Avoid overread.

Found-by: Mateusz "j00ru" Jurczyk and Gynvael Coldwind
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
Signed-off-by: Luca Barbato <lu_zero@gentoo.org>
jpeg2000: Calculate code-block coord in ff_jpeg2000_init_component()

Signed-off-by: Luca Barbato <lu_zero@gentoo.org>
Signed-off-by: Nicolas Bertrand <nicoinattendu@gmail.com>
Signed-off-by: Luca Barbato <lu_zero@gentoo.org>
jpeg2000: Check that nreslevels2decode has been initialized before use

Avoid buffer overread.

Found-by: Mateusz "j00ru" Jurczyk and Gynvael Coldwind
Signed-off-by: Luca Barbato <lu_zero@gentoo.org>
jpeg2000: Remove unneeded returns

Signed-off-by: Luca Barbato <lu_zero@gentoo.org>
jpeg2000: Initialize code blocks structures in precincts to 0

Prevent use of uninitialized memory / valgrind failure.

Found-by: ubitux
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
Signed-off-by: Luca Barbato <lu_zero@gentoo.org>
jpeg2000: Compute quantization for 'scalar derived' in the correct case.

Scalar derived case is represented by the JPEG2K_QSTY_SI define.

Signed-off-by: Luca Barbato <lu_zero@gentoo.org>
jpeg2000: Propagate error code from get_cox()

Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
Signed-off-by: Luca Barbato <lu_zero@gentoo.org>
jpeg2000: Check that there is a SOT before SOD

Avoid overreads.

Found-by: Mateusz "j00ru" Jurczyk and Gynvael Coldwind
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
Signed-off-by: Luca Barbato <lu_zero@gentoo.org>