File tree Expand file tree Collapse file tree 1 file changed +4
-1
lines changed
Expand file tree Collapse file tree 1 file changed +4
-1
lines changed Original file line number Diff line number Diff line change @@ -112,6 +112,9 @@ FLAC__bool bitwriter_grow_(FLAC__BitWriter *bw, uint32_t bits_to_add)
112112 uint32_t new_capacity ;
113113 bwword * new_buffer ;
114114
115+ /* Refuse to allocate more words than this amount, based on largest possible metadata chunk size */
116+ const uint32_t max_capacity = (((1u << FLAC__STREAM_METADATA_LENGTH_LEN ) - 1 ) * 8 + FLAC__STREAM_METADATA_LENGTH_LEN + FLAC__BITS_PER_WORD - 1 ) / FLAC__BITS_PER_WORD ;
117+
115118 FLAC__ASSERT (0 != bw );
116119 FLAC__ASSERT (0 != bw -> buffer );
117120
@@ -124,7 +127,7 @@ FLAC__bool bitwriter_grow_(FLAC__BitWriter *bw, uint32_t bits_to_add)
124127 if (bw -> capacity >= new_capacity )
125128 return true;
126129
127- if (new_capacity * sizeof ( bwword ) > ( 1u << FLAC__STREAM_METADATA_LENGTH_LEN ) )
130+ if (new_capacity > max_capacity )
128131 /* Requested new capacity is larger than the largest possible metadata block,
129132 * which is also larger than the largest sane framesize. That means something
130133 * went very wrong somewhere and previous checks failed.
You can’t perform that action at this time.
0 commit comments