Skip to content

Commit

Permalink
Fix HDFFR-82
Browse files Browse the repository at this point in the history
Description:
    A special bit, SZ_H4_REV_2, was used to indicate that the szip info
    was stored in a new way.  This bit was set in the options_mask field
    of the szip info struct.  As a result, the value of options_mask became
    incorrect.

    This PR removed the special bit from the options_mask before returning it
    to the application.  This change does not affect the data format in the
    file.
  • Loading branch information
bmribler committed Feb 1, 2024
1 parent 427aa23 commit 0fafc1e
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 6 deletions.
45 changes: 43 additions & 2 deletions hdf/src/cszip.c
Original file line number Diff line number Diff line change
Expand Up @@ -951,7 +951,7 @@ HCPcszip_endaccess(accrec_t *access_rec)
HCPsetup_szip_parms -- Initialize SZIP parameters
USAGE
intn HCPcszip_setup_parms( comp_info *c_info, int32 nt, int32 ndims, int32 *dims, int32 *cdims)
intn HCPsetup_szip_parms( comp_info *c_info, int32 nt, int32 ndims, int32 *dims, int32 *cdims)
comp_info *c_info; IN/OUT: the szip compression params
int32 nt; IN: the number type of the data
int32 ncomp; IN: components in GR, 1 for SD
Expand All @@ -969,7 +969,7 @@ HCPcszip_endaccess(accrec_t *access_rec)
pixels_per_scanline
bits_per_pixel
This is called from SDsetcompress, SDsetchunk, GRsetcompress, GRsetchunk
This is called from GRsetup_szip_parms and SDsetup_szip_parms
GLOBAL VARIABLES
COMMENTS, BUGS, ASSUMPTIONS
Expand Down Expand Up @@ -1059,3 +1059,44 @@ HCPsetup_szip_parms(comp_info *c_info, int32 nt, int32 ncomp, int32 ndims, int32
return FAIL;
#endif
}

/*--------------------------------------------------------------------------
NAME
HCPrm_szip_special_bit -- Removes the special bit that signals szip revised format
USAGE
intn HCPrm_szip_special_bit(comp_info *c_info)
comp_info *c_info; IN/OUT: the szip compression params
RETURNS
Returns SUCCEED
DESCRIPTION
A special bit, SZ_H4_REV_2, was introduced to indicate that the szip info
was stored in a new way. This bit was set in the options_mask field
of the szip info struct. As a result, the value of options_mask became
incorrect when the special bit was not removed from the options_mask before
returning to the application.
This is used in SDgetcompinfo and GRgetcompinfo.
--------------------------------------------------------------------------*/
intn
HCPrm_szip_special_bit(comp_info *c_info)
{
int sz_newway = 0; /* indicates the special bit presents in the options_mask */
intn ret_value = SUCCEED;

if (c_info == NULL)
HRETURN_ERROR(DFE_INTERNAL, FAIL);

/* if the special bit presents for SZIP compression, remove it to
return the correct options_mask */
sz_newway = (int)c_info->szip.options_mask & SZ_H4_REV_2;
if (sz_newway)
c_info->szip.options_mask = c_info->szip.options_mask & ~SZ_H4_REV_2;

done:
return SUCCEED;
}
1 change: 1 addition & 0 deletions hdf/src/hchunks.c
Original file line number Diff line number Diff line change
Expand Up @@ -1507,6 +1507,7 @@ HMCcreate(int32 file_id, /* IN: file to put chunked element in */
if (HCPdecode_header((uint8 *)info->comp_sp_tag_header, (comp_model_t *)&info->model_type,
info->minfo, (comp_coder_t *)&info->comp_type, info->cinfo) == FAIL)
HGOTO_ERROR(DFE_INTERNAL, FAIL);

break;
default:
/* Do nothing */
Expand Down
1 change: 1 addition & 0 deletions hdf/src/hproto.h
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,7 @@ HDFLIBAPI intn HCPdecode_header(uint8 *p, comp_model_t *model_type, model_info *

HDFLIBAPI intn HCPsetup_szip_parms(comp_info *c_info, int32 nt, int32 ncomp, int32 ndims, int32 *dims,
int32 *cdims);
HDFLIBAPI intn HCPrm_szip_special_bit(comp_info *c_info);
/*
** from hbuffer.c
*/
Expand Down
2 changes: 1 addition & 1 deletion mfhdf/dumper/testfiles/dumpsds-15szip.out
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ Variable Name = SDSszip
Type= 32-bit signed integer
Ref. = 6
Compression method = SZIP
Option mask = H4_SZ_EC_OPTION_MASK|H4_SZ_RAW_OPTION_MASK (65668)
Option mask = H4_SZ_EC_OPTION_MASK|H4_SZ_RAW_OPTION_MASK (132)
Pixels per block = 2
Pixels per scanline = 5
Bits per pixel = 32
Expand Down
8 changes: 7 additions & 1 deletion mfhdf/libsrc/mfsd.c
Original file line number Diff line number Diff line change
Expand Up @@ -4098,10 +4098,16 @@ SDgetcompinfo(int32 sdsid, /* IN: dataset ID */

/* use lower-level routine to get the compression information */
status = HCPgetcompinfo(handle->hdf_file, var->data_tag, var->data_ref, comp_type, c_info);

if (status == FAIL)
HGOTO_ERROR(DFE_INTERNAL, FAIL);

/* remove the szip special bit if necessary */
if (*comp_type == COMP_CODE_SZIP) {
status = HCPrm_szip_special_bit(c_info);
if (status == FAIL)
HGOTO_ERROR(DFE_INTERNAL, FAIL);
}

done:
return ret_value;
} /* SDgetcompinfo */
Expand Down
3 changes: 1 addition & 2 deletions mfhdf/test/tszip.c
Original file line number Diff line number Diff line change
Expand Up @@ -1089,8 +1089,7 @@ test_szip_unlimited()

/* Initialize for SZIP */
c_info.szip.pixels_per_block = 2;

c_info.szip.options_mask = SZ_EC_OPTION_MASK;
c_info.szip.options_mask = SZ_EC_OPTION_MASK;
c_info.szip.options_mask |= SZ_RAW_OPTION_MASK;
c_info.szip.bits_per_pixel = 0;
c_info.szip.pixels = 0;
Expand Down

0 comments on commit 0fafc1e

Please sign in to comment.