File tree Expand file tree Collapse file tree 1 file changed +8
-1
lines changed Expand file tree Collapse file tree 1 file changed +8
-1
lines changed Original file line number Diff line number Diff line change @@ -744,6 +744,7 @@ zfp_stream_maximum_size(const zfp_stream* zfp, const zfp_field* field)
744
744
size_t blocks = zfp_field_blocks (field );
745
745
uint values = 1u << (2 * dims );
746
746
uint maxbits = 0 ;
747
+ bitstream_size maxsize ;
747
748
748
749
if (!dims )
749
750
return 0 ;
@@ -766,7 +767,13 @@ zfp_stream_maximum_size(const zfp_stream* zfp, const zfp_field* field)
766
767
maxbits += values - 1 + values * MIN (zfp -> maxprec , zfp_field_precision (field ));
767
768
maxbits = MIN (maxbits , zfp -> maxbits );
768
769
maxbits = MAX (maxbits , zfp -> minbits );
769
- return ((ZFP_HEADER_MAX_BITS + blocks * maxbits + stream_word_bits - 1 ) & ~(stream_word_bits - 1 )) / CHAR_BIT ;
770
+
771
+ maxsize = ((ZFP_HEADER_MAX_BITS + ((bitstream_size )blocks ) * maxbits + stream_word_bits - 1 ) & ~(stream_word_bits - 1 )) / CHAR_BIT ;
772
+
773
+ /* check if the maxsize fits into size_t to avoid silent truncation */
774
+ if (((size_t )maxsize ) != maxsize )
775
+ return 0 ;
776
+ return (size_t )maxsize ;
770
777
}
771
778
772
779
void
You can’t perform that action at this time.
0 commit comments