Skip to content

Commit 4ed5926

Browse files
committed
Added verification that image has been set in SPECTRA.cc and check on the validity of the requested tile resolution in JTL.cc. Fixes a couple of the crash conditions reported in #223
1 parent 4db9fff commit 4ed5926

File tree

3 files changed

+32
-19
lines changed

3 files changed

+32
-19
lines changed

Diff for: ChangeLog

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
15/01/2022:
2+
- Added verification that image has been set in SPECTRA.cc and check on the validity of the requested tile
3+
resolution in JTL.cc. Fixes a couple of the crash conditions reported in https://github.com/ruven/iipsrv/issues/223
4+
5+
16
14/01/2022:
27
- Detection of HTJ2K also added for KakaduImage.cc for logging purposes (DEBUG needs to be enabled at compile time)
38

Diff for: src/JTL.cc

+18-13
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
IIP JTL Command Handler Class Member Function: Export a single tile
33
4-
Copyright (C) 2006-2021 Ruven Pillay.
4+
Copyright (C) 2006-2022 Ruven Pillay.
55
66
This program is free software; you can redistribute it and/or modify
77
it under the terms of the GNU General Public License as published by
@@ -43,6 +43,10 @@ void JTL::send( Session* session, int resolution, int tile ){
4343
if( session->loglevel >= 2 ) command_timer.start();
4444

4545

46+
// Need to know the number of resolutions
47+
int num_res = (*session->image)->getNumResolutions();
48+
49+
4650
// If we have requested a rotation, remap the tile index to rotated coordinates
4751
if( (int)((session->view)->getRotation()) % 360 == 90 ){
4852

@@ -51,7 +55,6 @@ void JTL::send( Session* session, int resolution, int tile ){
5155

5256
}
5357
else if( (int)((session->view)->getRotation()) % 360 == 180 ){
54-
int num_res = (*session->image)->getNumResolutions();
5558
unsigned int im_width = (*session->image)->image_widths[num_res-resolution-1];
5659
unsigned int im_height = (*session->image)->image_heights[num_res-resolution-1];
5760
unsigned int tw = (*session->image)->getTileWidth();
@@ -62,7 +65,7 @@ void JTL::send( Session* session, int resolution, int tile ){
6265

6366

6467
// Sanity check
65-
if( (resolution<0) || (tile<0) ){
68+
if( (resolution<0) || (tile<0) || (resolution>=num_res) ){
6669
ostringstream error;
6770
error << "JTL :: Invalid resolution/tile number: " << resolution << "," << tile;
6871
throw error.str();
@@ -120,18 +123,20 @@ void JTL::send( Session* session, int resolution, int tile ){
120123

121124

122125
// Set the physical output resolution for this particular view and zoom level
123-
int num_res = (*session->image)->getNumResolutions();
124-
unsigned int im_width = (*session->image)->image_widths[num_res-resolution-1];
125-
unsigned int im_height = (*session->image)->image_heights[num_res-resolution-1];
126-
float dpi_x = (*session->image)->dpi_x * (float) im_width / (float) (*session->image)->getImageWidth();
127-
float dpi_y = (*session->image)->dpi_y * (float) im_height / (float) (*session->image)->getImageHeight();
128-
compressor->setResolution( dpi_x, dpi_y, (*session->image)->dpi_units );
129-
130-
if( session->loglevel >= 5 ){
131-
*(session->logfile) << "JTL :: Setting physical resolution of tile to " << dpi_x << " x " << dpi_y
132-
<< ( ((*session->image)->dpi_units==1) ? " pixels/inch" : " pixels/cm" ) << endl;
126+
if( (*session->image)->dpi_x > 0 && (*session->image)->dpi_y > 0 ){
127+
unsigned int im_width = (*session->image)->image_widths[num_res-resolution-1];
128+
unsigned int im_height = (*session->image)->image_heights[num_res-resolution-1];
129+
float dpi_x = (*session->image)->dpi_x * ( (float)im_width / (float)(*session->image)->getImageWidth() );
130+
float dpi_y = (*session->image)->dpi_y * ( (float)im_height / (float)(*session->image)->getImageHeight() );
131+
compressor->setResolution( dpi_x, dpi_y, (*session->image)->dpi_units );
132+
133+
if( session->loglevel >= 5 ){
134+
*(session->logfile) << "JTL :: Setting physical resolution of tile to " << dpi_x << " x " << dpi_y
135+
<< ( ((*session->image)->dpi_units==1) ? " pixels/inch" : " pixels/cm" ) << endl;
136+
}
133137
}
134138

139+
135140
// Embed ICC profile
136141
if( session->view->embedICC() && ((*session->image)->getMetadata("icc").size()>0) ){
137142
if( session->loglevel >= 3 ){

Diff for: src/SPECTRA.cc

+9-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
IIP SPECTRA Command Handler Class Member Function
33
4-
Copyright (C) 2009-2021 Ruven Pillay.
4+
Copyright (C) 2009-2022 Ruven Pillay.
55
66
This program is free software; you can redistribute it and/or modify
77
it under the terms of the GNU General Public License as published by
@@ -36,7 +36,10 @@ void SPECTRA::run( Session* session, const std::string& argument ){
3636

3737
if( session->loglevel >= 3 ) (*session->logfile) << "SPECTRA handler reached" << endl;
3838

39-
int resolution, tile, x, y;
39+
40+
// Make sure we have set our image
41+
this->session = session;
42+
checkImage();
4043

4144

4245
// Time this command
@@ -46,19 +49,19 @@ void SPECTRA::run( Session* session, const std::string& argument ){
4649
// Parse the argument list
4750
string arg = argument;
4851
int delimitter = arg.find( "," );
49-
resolution = atoi( arg.substr(0,delimitter).c_str() );
52+
int resolution = atoi( arg.substr(0,delimitter).c_str() );
5053

5154
arg = arg.substr( delimitter + 1, arg.length() );
5255
delimitter = arg.find( "," );
53-
tile = atoi( arg.substr(0,delimitter).c_str() );
56+
int tile = atoi( arg.substr(0,delimitter).c_str() );
5457

5558
arg = arg.substr( delimitter + 1, arg.length() );
5659
delimitter = arg.find( "," );
57-
x = atoi( arg.substr(0,delimitter).c_str() );
60+
int x = atoi( arg.substr(0,delimitter).c_str() );
5861

5962
arg = arg.substr( delimitter + 1, arg.length() );
6063
delimitter = arg.find( "," );
61-
y = atoi( arg.substr(0,arg.length()).c_str() );
64+
int y = atoi( arg.substr(0,arg.length()).c_str() );
6265

6366
if( session->loglevel >= 5 ){
6467
(*session->logfile) << "SPECTRA :: resolution: " << resolution

0 commit comments

Comments
 (0)