@@ -118,7 +118,9 @@ namespace ojph {
118118 num_tiles.h = sz.get_image_extent ().y - sz.get_tile_offset ().y ;
119119 num_tiles.h = ojph_div_ceil (num_tiles.h , sz.get_tile_size ().h );
120120 if (num_tiles.area () > 65535 )
121- OJPH_ERROR (0x00030011 , " number of tiles cannot exceed 65535" );
121+ OJPH_ERROR (0x00030011 , " the number of tiles cannot exceed 65535" );
122+ if (num_tiles.area () == 0 )
123+ OJPH_ERROR (0x00030012 , " the number of tiles cannot be 0" );
122124
123125 // allocate tiles
124126 allocator->pre_alloc_obj <tile>((size_t )num_tiles.area ());
@@ -891,175 +893,181 @@ namespace ojph {
891893 if (sot.read (infile, resilient))
892894 {
893895 ui64 tile_start_location = (ui64)infile->tell ();
896+ bool skip_tile = false ;
894897
895- if (sot.get_tile_index () > (int )num_tiles.area ())
898+ if (sot.get_tile_index () >= (int )num_tiles.area ())
896899 {
897- if (resilient)
900+ if (resilient) {
898901 OJPH_INFO (0x00030061 , " wrong tile index" )
902+ skip_tile = true ; // skip the faulty tile
903+ }
899904 else
900905 OJPH_ERROR (0x00030061 , " wrong tile index" )
901906 }
902907
903- if (sot.get_tile_part_index ())
904- { // tile part
905- if (sot.get_num_tile_parts () &&
906- sot.get_tile_part_index () >= sot.get_num_tile_parts ())
907- {
908- if (resilient)
909- OJPH_INFO (0x00030062 ,
910- " error in tile part number, should be smaller than total"
911- " number of tile parts" )
912- else
913- OJPH_ERROR (0x00030062 ,
914- " error in tile part number, should be smaller than total"
915- " number of tile parts" )
916- }
917-
918- bool sod_found = false ;
919- ui16 other_tile_part_markers[7 ] = { SOT, POC, PPT, PLT, COM,
920- NLT, SOD };
921- while (true )
922- {
923- int marker_idx = 0 ;
924- int result = 0 ;
925- marker_idx = find_marker (infile, other_tile_part_markers + 1 , 6 );
926- if (marker_idx == 0 )
927- result = skip_marker (infile, " POC" ,
928- " POC marker segment in a tile is not supported yet" ,
929- OJPH_MSG_WARN, resilient);
930- else if (marker_idx == 1 )
931- result = skip_marker (infile, " PPT" ,
932- " PPT marker segment in a tile is not supported yet" ,
933- OJPH_MSG_WARN, resilient);
934- else if (marker_idx == 2 )
935- // Skipping PLT marker segment;this should not cause any issues
936- result = skip_marker (infile, " PLT" , NULL ,
937- OJPH_MSG_NO_MSG, resilient);
938- else if (marker_idx == 3 )
939- result = skip_marker (infile, " COM" , NULL ,
940- OJPH_MSG_NO_MSG, resilient);
941- else if (marker_idx == 4 )
942- result = skip_marker (infile, " NLT" ,
943- " NLT marker in tile is not supported yet" ,
944- OJPH_MSG_WARN, resilient);
945- else if (marker_idx == 5 )
946- {
947- sod_found = true ;
948- break ;
949- }
950-
951- if (marker_idx == -1 ) // marker not found
952- {
953- if (resilient)
954- OJPH_INFO (0x00030063 ,
955- " File terminated early before start of data is found"
956- " for tile indexed %d and tile part %d" ,
957- sot.get_tile_index (), sot.get_tile_part_index ())
958- else
959- OJPH_ERROR (0x00030063 ,
960- " File terminated early before start of data is found"
961- " for tile indexed %d and tile part %d" ,
962- sot.get_tile_index (), sot.get_tile_part_index ())
963- break ;
964- }
965- if (result == -1 ) // file terminated during marker seg. skipping
908+ if (!skip_tile)
909+ {
910+ if (sot.get_tile_part_index ())
911+ { // tile part
912+ if (sot.get_num_tile_parts () &&
913+ sot.get_tile_part_index () >= sot.get_num_tile_parts ())
966914 {
967915 if (resilient)
968- OJPH_INFO (0x00030064 ,
969- " File terminated during marker segment skipping" )
916+ OJPH_INFO (0x00030062 ,
917+ " error in tile part number, should be smaller than total"
918+ " number of tile parts" )
970919 else
971- OJPH_ERROR (0x00030064 ,
972- " File terminated during marker segment skipping" )
973- break ;
974- }
975- }
976- if (sod_found)
977- tiles[sot.get_tile_index ()].parse_tile_header (sot, infile,
978- tile_start_location);
979- }
980- else
981- { // first tile part
982- bool sod_found = false ;
983- ui16 first_tile_part_markers[12 ] = { SOT, COD, COC, QCD, QCC, RGN,
984- POC, PPT, PLT, COM, NLT, SOD };
985- while (true )
986- {
987- int marker_idx = 0 ;
988- int result = 0 ;
989- marker_idx = find_marker (infile, first_tile_part_markers+1 , 11 );
990- if (marker_idx == 0 )
991- result = skip_marker (infile, " COD" ,
992- " COD marker segment in a tile is not supported yet" ,
993- OJPH_MSG_WARN, resilient);
994- else if (marker_idx == 1 )
995- result = skip_marker (infile, " COC" ,
996- " COC marker segment in a tile is not supported yet" ,
997- OJPH_MSG_WARN, resilient);
998- else if (marker_idx == 2 )
999- result = skip_marker (infile, " QCD" ,
1000- " QCD marker segment in a tile is not supported yet" ,
1001- OJPH_MSG_WARN, resilient);
1002- else if (marker_idx == 3 )
1003- result = skip_marker (infile, " QCC" ,
1004- " QCC marker segment in a tile is not supported yet" ,
1005- OJPH_MSG_WARN, resilient);
1006- else if (marker_idx == 4 )
1007- result = skip_marker (infile, " RGN" ,
1008- " RGN marker segment in a tile is not supported yet" ,
1009- OJPH_MSG_WARN, resilient);
1010- else if (marker_idx == 5 )
1011- result = skip_marker (infile, " POC" ,
1012- " POC marker segment in a tile is not supported yet" ,
1013- OJPH_MSG_WARN, resilient);
1014- else if (marker_idx == 6 )
1015- result = skip_marker (infile, " PPT" ,
1016- " PPT marker segment in a tile is not supported yet" ,
1017- OJPH_MSG_WARN, resilient);
1018- else if (marker_idx == 7 )
1019- // Skipping PLT marker segment;this should not cause any issues
1020- result = skip_marker (infile, " PLT" , NULL ,
1021- OJPH_MSG_NO_MSG, resilient);
1022- else if (marker_idx == 8 )
1023- result = skip_marker (infile, " COM" , NULL ,
1024- OJPH_MSG_NO_MSG, resilient);
1025- else if (marker_idx == 9 )
1026- result = skip_marker (infile, " NLT" ,
1027- " PPT marker segment in a tile is not supported yet" ,
1028- OJPH_MSG_WARN, resilient);
1029- else if (marker_idx == 10 )
1030- {
1031- sod_found = true ;
1032- break ;
920+ OJPH_ERROR (0x00030062 ,
921+ " error in tile part number, should be smaller than total"
922+ " number of tile parts" )
1033923 }
1034924
1035- if (marker_idx == -1 ) // marker not found
925+ bool sod_found = false ;
926+ ui16 other_tile_part_markers[7 ] = { SOT, POC, PPT, PLT, COM,
927+ NLT, SOD };
928+ while (true )
1036929 {
1037- if (resilient)
1038- OJPH_INFO (0x00030065 ,
1039- " File terminated early before start of data is found"
1040- " for tile indexed %d and tile part %d" ,
1041- sot.get_tile_index (), sot.get_tile_part_index ())
1042- else
1043- OJPH_ERROR (0x00030065 ,
1044- " File terminated early before start of data is found"
1045- " for tile indexed %d and tile part %d" ,
1046- sot.get_tile_index (), sot.get_tile_part_index ())
1047- break ;
930+ int marker_idx = 0 ;
931+ int result = 0 ;
932+ marker_idx = find_marker (infile, other_tile_part_markers+1 , 6 );
933+ if (marker_idx == 0 )
934+ result = skip_marker (infile, " POC" ,
935+ " POC marker segment in a tile is not supported yet" ,
936+ OJPH_MSG_WARN, resilient);
937+ else if (marker_idx == 1 )
938+ result = skip_marker (infile, " PPT" ,
939+ " PPT marker segment in a tile is not supported yet" ,
940+ OJPH_MSG_WARN, resilient);
941+ else if (marker_idx == 2 )
942+ // Skipping PLT marker segment;this should not cause any issues
943+ result = skip_marker (infile, " PLT" , NULL ,
944+ OJPH_MSG_NO_MSG, resilient);
945+ else if (marker_idx == 3 )
946+ result = skip_marker (infile, " COM" , NULL ,
947+ OJPH_MSG_NO_MSG, resilient);
948+ else if (marker_idx == 4 )
949+ result = skip_marker (infile, " NLT" ,
950+ " NLT marker in tile is not supported yet" ,
951+ OJPH_MSG_WARN, resilient);
952+ else if (marker_idx == 5 )
953+ {
954+ sod_found = true ;
955+ break ;
956+ }
957+
958+ if (marker_idx == -1 ) // marker not found
959+ {
960+ if (resilient)
961+ OJPH_INFO (0x00030063 ,
962+ " File terminated early before start of data is found"
963+ " for tile indexed %d and tile part %d" ,
964+ sot.get_tile_index (), sot.get_tile_part_index ())
965+ else
966+ OJPH_ERROR (0x00030063 ,
967+ " File terminated early before start of data is found"
968+ " for tile indexed %d and tile part %d" ,
969+ sot.get_tile_index (), sot.get_tile_part_index ())
970+ break ;
971+ }
972+ if (result == -1 ) // file terminated during marker seg. skipping
973+ {
974+ if (resilient)
975+ OJPH_INFO (0x00030064 ,
976+ " File terminated during marker segment skipping" )
977+ else
978+ OJPH_ERROR (0x00030064 ,
979+ " File terminated during marker segment skipping" )
980+ break ;
981+ }
1048982 }
1049- if (result == -1 ) // file terminated during marker seg. skipping
983+ if (sod_found)
984+ tiles[sot.get_tile_index ()].parse_tile_header (sot, infile,
985+ tile_start_location);
986+ }
987+ else
988+ { // first tile part
989+ bool sod_found = false ;
990+ ui16 first_tile_part_markers[12 ] = { SOT, COD, COC, QCD, QCC, RGN,
991+ POC, PPT, PLT, COM, NLT, SOD };
992+ while (true )
1050993 {
1051- if (resilient)
1052- OJPH_INFO (0x00030066 ,
1053- " File terminated during marker segment skipping" )
1054- else
1055- OJPH_ERROR (0x00030066 ,
1056- " File terminated during marker segment skipping" )
1057- break ;
994+ int marker_idx = 0 ;
995+ int result = 0 ;
996+ marker_idx = find_marker (infile, first_tile_part_markers+1 , 11 );
997+ if (marker_idx == 0 )
998+ result = skip_marker (infile, " COD" ,
999+ " COD marker segment in a tile is not supported yet" ,
1000+ OJPH_MSG_WARN, resilient);
1001+ else if (marker_idx == 1 )
1002+ result = skip_marker (infile, " COC" ,
1003+ " COC marker segment in a tile is not supported yet" ,
1004+ OJPH_MSG_WARN, resilient);
1005+ else if (marker_idx == 2 )
1006+ result = skip_marker (infile, " QCD" ,
1007+ " QCD marker segment in a tile is not supported yet" ,
1008+ OJPH_MSG_WARN, resilient);
1009+ else if (marker_idx == 3 )
1010+ result = skip_marker (infile, " QCC" ,
1011+ " QCC marker segment in a tile is not supported yet" ,
1012+ OJPH_MSG_WARN, resilient);
1013+ else if (marker_idx == 4 )
1014+ result = skip_marker (infile, " RGN" ,
1015+ " RGN marker segment in a tile is not supported yet" ,
1016+ OJPH_MSG_WARN, resilient);
1017+ else if (marker_idx == 5 )
1018+ result = skip_marker (infile, " POC" ,
1019+ " POC marker segment in a tile is not supported yet" ,
1020+ OJPH_MSG_WARN, resilient);
1021+ else if (marker_idx == 6 )
1022+ result = skip_marker (infile, " PPT" ,
1023+ " PPT marker segment in a tile is not supported yet" ,
1024+ OJPH_MSG_WARN, resilient);
1025+ else if (marker_idx == 7 )
1026+ // Skipping PLT marker segment;this should not cause any issues
1027+ result = skip_marker (infile, " PLT" , NULL ,
1028+ OJPH_MSG_NO_MSG, resilient);
1029+ else if (marker_idx == 8 )
1030+ result = skip_marker (infile, " COM" , NULL ,
1031+ OJPH_MSG_NO_MSG, resilient);
1032+ else if (marker_idx == 9 )
1033+ result = skip_marker (infile, " NLT" ,
1034+ " PPT marker segment in a tile is not supported yet" ,
1035+ OJPH_MSG_WARN, resilient);
1036+ else if (marker_idx == 10 )
1037+ {
1038+ sod_found = true ;
1039+ break ;
1040+ }
1041+
1042+ if (marker_idx == -1 ) // marker not found
1043+ {
1044+ if (resilient)
1045+ OJPH_INFO (0x00030065 ,
1046+ " File terminated early before start of data is found"
1047+ " for tile indexed %d and tile part %d" ,
1048+ sot.get_tile_index (), sot.get_tile_part_index ())
1049+ else
1050+ OJPH_ERROR (0x00030065 ,
1051+ " File terminated early before start of data is found"
1052+ " for tile indexed %d and tile part %d" ,
1053+ sot.get_tile_index (), sot.get_tile_part_index ())
1054+ break ;
1055+ }
1056+ if (result == -1 ) // file terminated during marker seg. skipping
1057+ {
1058+ if (resilient)
1059+ OJPH_INFO (0x00030066 ,
1060+ " File terminated during marker segment skipping" )
1061+ else
1062+ OJPH_ERROR (0x00030066 ,
1063+ " File terminated during marker segment skipping" )
1064+ break ;
1065+ }
10581066 }
1067+ if (sod_found)
1068+ tiles[sot.get_tile_index ()].parse_tile_header (sot, infile,
1069+ tile_start_location);
10591070 }
1060- if (sod_found)
1061- tiles[sot.get_tile_index ()].parse_tile_header (sot, infile,
1062- tile_start_location);
10631071 }
10641072 }
10651073
0 commit comments