Skip to content

Commit 7685744

Browse files
committed
Fixes a bug that was discovered during OSS-Fuzz.
1 parent 8120253 commit 7685744

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

src/core/codestream/ojph_params.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -976,7 +976,7 @@ namespace ojph {
976976
if (file->read(&SPcod.wavelet_trans, 1) != 1)
977977
OJPH_ERROR(0x0005007A, "error reading COD segment");
978978

979-
if (((SPcod.num_decomp & 0x80) == 0 && SPcod.num_decomp > 32)
979+
if (get_num_decompositions() > 32
980980
|| SPcod.block_width > 8
981981
|| SPcod.block_height > 8
982982
|| SPcod.block_width + SPcod.block_height > 8
@@ -987,8 +987,9 @@ namespace ojph {
987987
|| (SPcod.block_style & 0xB7) != 0x00)
988988
OJPH_ERROR(0x0005007E, "unsupported settings in a COD-SPcod parameter");
989989

990+
ui8 num_decompositions = get_num_decompositions();
990991
if (Scod & 1)
991-
for (int i = 0; i <= SPcod.num_decomp; ++i)
992+
for (int i = 0; i <= num_decompositions; ++i)
992993
if (file->read(&SPcod.precinct_size[i], 1) != 1)
993994
OJPH_ERROR(0x0005007B, "error reading COD segment");
994995
if (Lcod != 12 + ((Scod & 1) ? 1 + SPcod.num_decomp : 0))
@@ -1034,7 +1035,7 @@ namespace ojph {
10341035
if (file->read(&SPcod.wavelet_trans, 1) != 1)
10351036
OJPH_ERROR(0x00050129, "error reading COC segment");
10361037

1037-
if (((SPcod.num_decomp & 0x80) == 0 && SPcod.num_decomp > 32)
1038+
if (get_num_decompositions() > 32
10381039
|| SPcod.block_width > 8
10391040
|| SPcod.block_height > 8
10401041
|| SPcod.block_width + SPcod.block_height > 8
@@ -1045,13 +1046,14 @@ namespace ojph {
10451046
|| (SPcod.block_style & 0xB7) != 0x00)
10461047
OJPH_ERROR(0x0005012D, "unsupported settings in a COC-SPcoc parameter");
10471048

1049+
ui8 num_decompositions = get_num_decompositions();
10481050
if (Scod & 1)
1049-
for (int i = 0; i <= get_num_decompositions(); ++i)
1051+
for (int i = 0; i <= num_decompositions; ++i)
10501052
if (file->read(&SPcod.precinct_size[i], 1) != 1)
10511053
OJPH_ERROR(0x0005012A, "error reading COC segment");
10521054
ui32 t = 9;
10531055
t += num_comps < 257 ? 0 : 1;
1054-
t += (Scod & 1) ? 1 + get_num_decompositions() : 0;
1056+
t += (Scod & 1) ? 1 + num_decompositions : 0;
10551057
if (Lcod != t)
10561058
OJPH_ERROR(0x0005012B, "error in COC segment length");
10571059
}

0 commit comments

Comments
 (0)