Skip to content

Commit e0ecd0d

Browse files
authored
Detecting illegal precinct width or height (#269)
* Detect illegal precincts which has a width or height of 1 in resolutions other than the coarsest. * removing trailing spaes
1 parent c3a6d8e commit e0ecd0d

2 files changed

Lines changed: 51 additions & 29 deletions

File tree

src/core/codestream/ojph_params.cpp

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -992,10 +992,21 @@ namespace ojph {
992992
OJPH_ERROR(0x0005007E, "unsupported settings in a COD-SPcod parameter");
993993

994994
ui8 num_decompositions = get_num_decompositions();
995-
if (Scod & 1)
996-
for (int i = 0; i <= num_decompositions; ++i)
995+
if (Scod & 1) {
996+
for (int i = 0; i <= num_decompositions; ++i) {
997997
if (file->read(&SPcod.precinct_size[i], 1) != 1)
998998
OJPH_ERROR(0x0005007B, "error reading COD segment");
999+
if (i)
1000+
if ((SPcod.precinct_size[i] & 0x0F) == 0 ||
1001+
(SPcod.precinct_size[i] >> 4) == 0)
1002+
OJPH_ERROR(0x0005007F,
1003+
"Precinct width or height for resolutions other than the"
1004+
" coarsest must be larger than 1; here, they are %d and %d,"
1005+
" respectively.",
1006+
1 << (SPcod.precinct_size[i] & 0x0F),
1007+
1 << (SPcod.precinct_size[i] >> 4));
1008+
}
1009+
}
9991010
if (Lcod != 12 + ((Scod & 1) ? 1 + SPcod.num_decomp : 0))
10001011
OJPH_ERROR(0x0005007C, "error in COD segment length");
10011012
}
@@ -1051,10 +1062,21 @@ namespace ojph {
10511062
OJPH_ERROR(0x0005012D, "unsupported settings in a COC-SPcoc parameter");
10521063

10531064
ui8 num_decompositions = get_num_decompositions();
1054-
if (Scod & 1)
1055-
for (int i = 0; i <= num_decompositions; ++i)
1065+
if (Scod & 1) {
1066+
for (int i = 0; i <= num_decompositions; ++i) {
10561067
if (file->read(&SPcod.precinct_size[i], 1) != 1)
10571068
OJPH_ERROR(0x0005012A, "error reading COC segment");
1069+
if (i)
1070+
if ((SPcod.precinct_size[i] & 0x0F) == 0 ||
1071+
(SPcod.precinct_size[i] >> 4) == 0)
1072+
OJPH_ERROR(0x0005012E,
1073+
"Precinct width or height for resolutions other than the"
1074+
" coarsest must be larger than 1; here, they are %d and %d,"
1075+
" respectively.",
1076+
1 << (SPcod.precinct_size[i] & 0x0F),
1077+
1 << (SPcod.precinct_size[i] >> 4));
1078+
}
1079+
}
10581080
ui32 t = 9;
10591081
t += num_comps < 257 ? 0 : 1;
10601082
t += (Scod & 1) ? 1 + num_decompositions : 0;

src/core/codestream/ojph_resolution.cpp

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,21 @@
22
// This software is released under the 2-Clause BSD license, included
33
// below.
44
//
5-
// Copyright (c) 2019, Aous Naman
5+
// Copyright (c) 2019, Aous Naman
66
// Copyright (c) 2019, Kakadu Software Pty Ltd, Australia
77
// Copyright (c) 2019, The University of New South Wales, Australia
8-
//
8+
//
99
// Redistribution and use in source and binary forms, with or without
1010
// modification, are permitted provided that the following conditions are
1111
// met:
12-
//
12+
//
1313
// 1. Redistributions of source code must retain the above copyright
1414
// notice, this list of conditions and the following disclaimer.
15-
//
15+
//
1616
// 2. Redistributions in binary form must reproduce the above copyright
1717
// notice, this list of conditions and the following disclaimer in the
1818
// documentation and/or other materials provided with the distribution.
19-
//
19+
//
2020
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
2121
// IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
2222
// TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
@@ -57,7 +57,7 @@ namespace ojph {
5757
{
5858
//////////////////////////////////////////////////////////////////////////
5959
void resolution::pre_alloc(codestream* codestream, const rect& res_rect,
60-
const rect& recon_res_rect,
60+
const rect& recon_res_rect,
6161
ui32 comp_num, ui32 res_num)
6262
{
6363
mem_fixed_allocator* allocator = codestream->get_allocator();
@@ -150,7 +150,7 @@ namespace ojph {
150150
tby1 = try1 >> 1;
151151
re.org.y = tby0;
152152
re.siz.h = tby1 - tby0;
153-
subband::pre_alloc(codestream, re, comp_num, res_num,
153+
subband::pre_alloc(codestream, re, comp_num, res_num,
154154
transform_flags);
155155
}
156156
else if (ds == param_dfs::HORZ_DWT)
@@ -170,7 +170,7 @@ namespace ojph {
170170
tbx1 = trx1 >> 1;
171171
re.org.x = tbx0;
172172
re.siz.w = tbx1 - tbx0;
173-
subband::pre_alloc(codestream, re, comp_num, res_num,
173+
subband::pre_alloc(codestream, re, comp_num, res_num,
174174
transform_flags);
175175
}
176176
else
@@ -183,7 +183,7 @@ namespace ojph {
183183
}
184184
}
185185
else
186-
subband::pre_alloc(codestream, res_rect, comp_num, res_num,
186+
subband::pre_alloc(codestream, res_rect, comp_num, res_num,
187187
transform_flags);
188188

189189
//prealloc precincts
@@ -219,7 +219,7 @@ namespace ojph {
219219
allocator->pre_alloc_data<si32>(width, 1);
220220
allocator->pre_alloc_data<si32>(width, 1);
221221
}
222-
else
222+
else
223223
{
224224
for (ui32 i = 0; i < num_steps; ++i)
225225
allocator->pre_alloc_data<si64>(width, 1);
@@ -328,7 +328,7 @@ namespace ojph {
328328
child_res = allocator->post_alloc_obj<resolution>(1);
329329
child_res->finalize_alloc(codestream, re,
330330
skipped_res_for_recon ? recon_res_rect : re, comp_num,
331-
res_num - 1, comp_downsamp, next_res_downsamp,
331+
res_num - 1, comp_downsamp, next_res_downsamp,
332332
parent_tile_comp, this);
333333
}
334334
else
@@ -407,7 +407,7 @@ namespace ojph {
407407
num_precincts.w -= trx0 >> log_PP.w;
408408
num_precincts.h = (try1 + (1 << log_PP.h) - 1) >> log_PP.h;
409409
num_precincts.h -= try0 >> log_PP.h;
410-
precincts =
410+
precincts =
411411
allocator->post_alloc_obj<precinct>((size_t)num_precincts.area());
412412
ui64 num = num_precincts.area();
413413
for (ui64 i = 0; i < num; ++i)
@@ -508,7 +508,7 @@ namespace ojph {
508508
allocator->post_alloc_data<si64>(width, 1), width, 1);
509509
}
510510
}
511-
else
511+
else
512512
{
513513
for (ui32 i = 0; i < num_steps; ++i)
514514
ssp[i].line->wrap(
@@ -528,7 +528,7 @@ namespace ojph {
528528

529529
//////////////////////////////////////////////////////////////////////////
530530
line_buf* resolution::get_line()
531-
{
531+
{
532532
if (vert_even)
533533
{
534534
++cur_line;
@@ -742,11 +742,11 @@ namespace ojph {
742742
{
743743
if (vert_even) { // even
744744
if (transform_flags & HORZ_TRX)
745-
rev_horz_syn(atk, aug->line, child_res->pull_line(),
745+
rev_horz_syn(atk, aug->line, child_res->pull_line(),
746746
bands[1].pull_line(), width, horz_even);
747747
else
748748
memcpy(aug->line->p, child_res->pull_line()->p,
749-
(size_t)width
749+
(size_t)width
750750
* (aug->line->flags & line_buf::LFT_SIZE_MASK));
751751
aug->active = true;
752752
vert_even = !vert_even;
@@ -755,11 +755,11 @@ namespace ojph {
755755
}
756756
else {
757757
if (transform_flags & HORZ_TRX)
758-
rev_horz_syn(atk, sig->line, bands[2].pull_line(),
758+
rev_horz_syn(atk, sig->line, bands[2].pull_line(),
759759
bands[3].pull_line(), width, horz_even);
760760
else
761761
memcpy(sig->line->p, bands[2].pull_line()->p,
762-
(size_t)width
762+
(size_t)width
763763
* (sig->line->flags & line_buf::LFT_SIZE_MASK));
764764
sig->active = true;
765765
vert_even = !vert_even;
@@ -799,7 +799,7 @@ namespace ojph {
799799
bands[1].pull_line(), width, horz_even);
800800
else
801801
memcpy(aug->line->p, child_res->pull_line()->p,
802-
(size_t)width
802+
(size_t)width
803803
* (aug->line->flags & line_buf::LFT_SIZE_MASK));
804804
}
805805
else
@@ -809,11 +809,11 @@ namespace ojph {
809809
bands[3].pull_line(), width, horz_even);
810810
else
811811
memcpy(aug->line->p, bands[2].pull_line()->p,
812-
(size_t)width
812+
(size_t)width
813813
* (aug->line->flags & line_buf::LFT_SIZE_MASK));
814814
if (aug->line->flags & line_buf::LFT_32BIT)
815815
{
816-
si32* sp = aug->line->i32;
816+
si32* sp = aug->line->i32;
817817
for (ui32 i = width; i > 0; --i)
818818
*sp++ >>= 1;
819819
}
@@ -843,9 +843,9 @@ namespace ojph {
843843
{
844844
if (vert_even) { // even
845845
if (transform_flags & HORZ_TRX)
846-
irv_horz_syn(atk, aug->line, child_res->pull_line(),
846+
irv_horz_syn(atk, aug->line, child_res->pull_line(),
847847
bands[1].pull_line(), width, horz_even);
848-
else
848+
else
849849
memcpy(aug->line->f32, child_res->pull_line()->f32,
850850
width * sizeof(float));
851851
aug->active = true;
@@ -859,7 +859,7 @@ namespace ojph {
859859
}
860860
else {
861861
if (transform_flags & HORZ_TRX)
862-
irv_horz_syn(atk, sig->line, bands[2].pull_line(),
862+
irv_horz_syn(atk, sig->line, bands[2].pull_line(),
863863
bands[3].pull_line(), width, horz_even);
864864
else
865865
memcpy(sig->line->f32, bands[2].pull_line()->f32,
@@ -924,7 +924,7 @@ namespace ojph {
924924
}
925925
}
926926
else
927-
{
927+
{
928928
if (reversible)
929929
{
930930
if (transform_flags & HORZ_TRX)

0 commit comments

Comments
 (0)