mirror of
https://github.com/HDFGroup/hdf5.git
synced 2025-01-30 15:32:37 +08:00
[svn-r9924] Purpose:
Bug fix (#56) Description: h52gif creash for data > 1 byt Solution: check datatype and return with error message if not 1 byte int Platforms tested: shanti,verbena Misc. update:
This commit is contained in:
parent
c9c1277401
commit
d0ced67f52
@ -211,7 +211,7 @@ int main(int argc , char **argv)
|
||||
*/
|
||||
if (ReadHDF(&Image, GlobalPalette, dim_sizes, HDFName,
|
||||
image_name_arr[idx], pal_name_arr[idx]) < 0) {
|
||||
fprintf(stderr , "Unable to read HDF file\n");
|
||||
fprintf(stderr , "Unable to read image %s from HDF file %s\n",image_name_arr[idx],HDFName);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -44,9 +44,11 @@ int ReadHDF(BYTE** data, BYTE palette[256][3], hsize_t *image_size,
|
||||
{
|
||||
hid_t fHfile; /* H5 file to open */
|
||||
hid_t dspace; /* dataspace identifier for the the dataset */
|
||||
hid_t dtype; /* datatype identifier for the the dataset */
|
||||
hid_t dset; /* dataset identifier */
|
||||
hid_t pal_set; /* dataset for palette */
|
||||
hid_t pal_space; /* dataspace for palette */
|
||||
hid_t pal_dtype; /* datatype for palette */
|
||||
hsize_t datasize; /* size of the image */
|
||||
int pal_exist = 0; /* do we have a palette? */
|
||||
|
||||
@ -74,6 +76,20 @@ int ReadHDF(BYTE** data, BYTE palette[256][3], hsize_t *image_size,
|
||||
return -1;
|
||||
}
|
||||
|
||||
dtype = H5Dget_type(dset);
|
||||
if (dtype < 0) {
|
||||
fprintf(stderr , "Unable to open datatype\n");
|
||||
return -1;
|
||||
}
|
||||
if (H5Tget_class(dtype) != H5T_INTEGER) {
|
||||
fprintf(stderr , "Data is not integer. Cannot convert to GIF\n");
|
||||
return -1;
|
||||
}
|
||||
if (H5Tget_size(dtype) != 1) {
|
||||
fprintf(stderr , "Data is %d bytes per pixel. Cannot convert to GIF\n",H5Tget_size(dtype));
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* get the dataspace */
|
||||
if ((dspace = H5Dget_space(dset)) < 0) {
|
||||
fprintf(stderr , "Unable to get dataspace\n");
|
||||
@ -96,7 +112,7 @@ int ReadHDF(BYTE** data, BYTE palette[256][3], hsize_t *image_size,
|
||||
}
|
||||
|
||||
/* get the actual image */
|
||||
if (H5Dread(dset , H5Dget_type(dset) , H5S_ALL , H5S_ALL , H5P_DEFAULT , *data) < 0) {
|
||||
if (H5Dread(dset , H5Tget_native_type(dtype, H5T_DIR_ASCEND) , H5S_ALL , H5S_ALL , H5P_DEFAULT , *data) < 0) {
|
||||
fprintf(stderr , "Unable to read data \n");
|
||||
cleanup(*data);
|
||||
return -1;
|
||||
@ -115,6 +131,20 @@ int ReadHDF(BYTE** data, BYTE palette[256][3], hsize_t *image_size,
|
||||
return -1;
|
||||
}
|
||||
|
||||
pal_dtype = H5Dget_type(pal_set);
|
||||
if (dtype < 0) {
|
||||
fprintf(stderr , "Unable to open palette datatype\n");
|
||||
return -1;
|
||||
}
|
||||
if (H5Tget_class(pal_dtype) != H5T_INTEGER) {
|
||||
fprintf(stderr , "Palette data is not integer. Cannot convert to GIF\n");
|
||||
return -1;
|
||||
}
|
||||
if (H5Tget_size(pal_dtype) != 1) {
|
||||
fprintf(stderr , "Palette data is %d bytes per pixel. Cannot convert to GIF\n",H5Tget_size(pal_dtype));
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* get the dataspace */
|
||||
if ((pal_space = H5Dget_space(pal_set)) < 0) {
|
||||
fprintf(stderr , "Unable to get dataspace\n");
|
||||
@ -147,7 +177,7 @@ int ReadHDF(BYTE** data, BYTE palette[256][3], hsize_t *image_size,
|
||||
}
|
||||
|
||||
/* get the actual palette */
|
||||
if (H5Dread(pal_set , H5Dget_type(pal_set) , H5S_ALL , H5S_ALL , H5P_DEFAULT , temp_buf) < 0) {
|
||||
if (H5Dread(pal_set , H5Tget_native_type(pal_dtype, H5T_DIR_ASCEND) , H5S_ALL , H5S_ALL , H5P_DEFAULT , temp_buf) < 0) {
|
||||
fprintf(stderr , "Unable to read data \n");
|
||||
cleanup(*data);
|
||||
cleanup(temp_buf);
|
||||
|
@ -211,7 +211,7 @@ int main(int argc , char **argv)
|
||||
*/
|
||||
if (ReadHDF(&Image, GlobalPalette, dim_sizes, HDFName,
|
||||
image_name_arr[idx], pal_name_arr[idx]) < 0) {
|
||||
fprintf(stderr , "Unable to read HDF file\n");
|
||||
fprintf(stderr , "Unable to read image %s from HDF file %s\n",image_name_arr[idx],HDFName);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -44,9 +44,11 @@ int ReadHDF(BYTE** data, BYTE palette[256][3], hsize_t *image_size,
|
||||
{
|
||||
hid_t fHfile; /* H5 file to open */
|
||||
hid_t dspace; /* dataspace identifier for the the dataset */
|
||||
hid_t dtype; /* datatype identifier for the the dataset */
|
||||
hid_t dset; /* dataset identifier */
|
||||
hid_t pal_set; /* dataset for palette */
|
||||
hid_t pal_space; /* dataspace for palette */
|
||||
hid_t pal_dtype; /* datatype for palette */
|
||||
hsize_t datasize; /* size of the image */
|
||||
int pal_exist = 0; /* do we have a palette? */
|
||||
|
||||
@ -74,6 +76,20 @@ int ReadHDF(BYTE** data, BYTE palette[256][3], hsize_t *image_size,
|
||||
return -1;
|
||||
}
|
||||
|
||||
dtype = H5Dget_type(dset);
|
||||
if (dtype < 0) {
|
||||
fprintf(stderr , "Unable to open datatype\n");
|
||||
return -1;
|
||||
}
|
||||
if (H5Tget_class(dtype) != H5T_INTEGER) {
|
||||
fprintf(stderr , "Data is not integer. Cannot convert to GIF\n");
|
||||
return -1;
|
||||
}
|
||||
if (H5Tget_size(dtype) != 1) {
|
||||
fprintf(stderr , "Data is %d bytes per pixel. Cannot convert to GIF\n",H5Tget_size(dtype));
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* get the dataspace */
|
||||
if ((dspace = H5Dget_space(dset)) < 0) {
|
||||
fprintf(stderr , "Unable to get dataspace\n");
|
||||
@ -96,7 +112,7 @@ int ReadHDF(BYTE** data, BYTE palette[256][3], hsize_t *image_size,
|
||||
}
|
||||
|
||||
/* get the actual image */
|
||||
if (H5Dread(dset , H5Dget_type(dset) , H5S_ALL , H5S_ALL , H5P_DEFAULT , *data) < 0) {
|
||||
if (H5Dread(dset , H5Tget_native_type(dtype, H5T_DIR_ASCEND) , H5S_ALL , H5S_ALL , H5P_DEFAULT , *data) < 0) {
|
||||
fprintf(stderr , "Unable to read data \n");
|
||||
cleanup(*data);
|
||||
return -1;
|
||||
@ -115,6 +131,20 @@ int ReadHDF(BYTE** data, BYTE palette[256][3], hsize_t *image_size,
|
||||
return -1;
|
||||
}
|
||||
|
||||
pal_dtype = H5Dget_type(pal_set);
|
||||
if (dtype < 0) {
|
||||
fprintf(stderr , "Unable to open palette datatype\n");
|
||||
return -1;
|
||||
}
|
||||
if (H5Tget_class(pal_dtype) != H5T_INTEGER) {
|
||||
fprintf(stderr , "Palette data is not integer. Cannot convert to GIF\n");
|
||||
return -1;
|
||||
}
|
||||
if (H5Tget_size(pal_dtype) != 1) {
|
||||
fprintf(stderr , "Palette data is %d bytes per pixel. Cannot convert to GIF\n",H5Tget_size(pal_dtype));
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* get the dataspace */
|
||||
if ((pal_space = H5Dget_space(pal_set)) < 0) {
|
||||
fprintf(stderr , "Unable to get dataspace\n");
|
||||
@ -147,7 +177,7 @@ int ReadHDF(BYTE** data, BYTE palette[256][3], hsize_t *image_size,
|
||||
}
|
||||
|
||||
/* get the actual palette */
|
||||
if (H5Dread(pal_set , H5Dget_type(pal_set) , H5S_ALL , H5S_ALL , H5P_DEFAULT , temp_buf) < 0) {
|
||||
if (H5Dread(pal_set , H5Tget_native_type(pal_dtype, H5T_DIR_ASCEND) , H5S_ALL , H5S_ALL , H5P_DEFAULT , temp_buf) < 0) {
|
||||
fprintf(stderr , "Unable to read data \n");
|
||||
cleanup(*data);
|
||||
cleanup(temp_buf);
|
||||
|
Loading…
Reference in New Issue
Block a user