mirror of
https://github.com/intel/isa-l.git
synced 2025-01-05 22:59:52 +01:00
igzip: Fix out buffer overflow in write_type0_header
Fix a possible 1 byte overflow by creating a combined write_bits and flush. Change-Id: I2d2455e9e32a820522ff1d89d016db72a82baed9 Signed-off-by: Roy Oursler <roy.j.oursler@intel.com>
This commit is contained in:
parent
5d413c8b12
commit
e3fad7c45a
@ -95,6 +95,19 @@ static inline void flush_bits(struct BitBuf2 *me)
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Can write up to 8 bytes to output buffer */
|
||||||
|
static inline void flush(struct BitBuf2 *me)
|
||||||
|
{
|
||||||
|
uint32_t bytes;
|
||||||
|
if (me->m_bit_count) {
|
||||||
|
_mm_stream_si64x((int64_t *) me->m_out_buf, me->m_bits);
|
||||||
|
bytes = (me->m_bit_count + 7) / 8;
|
||||||
|
me->m_out_buf += bytes;
|
||||||
|
}
|
||||||
|
me->m_bits = 0;
|
||||||
|
me->m_bit_count = 0;
|
||||||
|
}
|
||||||
|
|
||||||
static inline void check_space(struct BitBuf2 *me, uint32_t num_bits)
|
static inline void check_space(struct BitBuf2 *me, uint32_t num_bits)
|
||||||
{
|
{
|
||||||
/* Checks if bitbuf has num_bits extra space and flushes the bytes in
|
/* Checks if bitbuf has num_bits extra space and flushes the bytes in
|
||||||
@ -116,17 +129,11 @@ static inline void write_bits(struct BitBuf2 *me, uint64_t code, uint32_t count)
|
|||||||
flush_bits(me);
|
flush_bits(me);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Can write up to 8 bytes to output buffer */
|
static inline void write_bits_flush(struct BitBuf2 *me, uint64_t code, uint32_t count)
|
||||||
static inline void flush(struct BitBuf2 *me)
|
{ /* Assumes there is space to fit code into m_bits. */
|
||||||
{
|
me->m_bits |= code << me->m_bit_count;
|
||||||
uint32_t bytes;
|
me->m_bit_count += count;
|
||||||
if (me->m_bit_count) {
|
flush(me);
|
||||||
_mm_stream_si64x((int64_t *) me->m_out_buf, me->m_bits);
|
|
||||||
bytes = (me->m_bit_count + 7) / 8;
|
|
||||||
me->m_out_buf += bytes;
|
|
||||||
}
|
|
||||||
me->m_bits = 0;
|
|
||||||
me->m_bit_count = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif //BITBUF2_H
|
#endif //BITBUF2_H
|
||||||
|
@ -797,8 +797,7 @@ static void write_type0_header(struct isal_zstream *stream)
|
|||||||
memcpy(stream->next_out, &stored_blk_hdr, memcpy_len);
|
memcpy(stream->next_out, &stored_blk_hdr, memcpy_len);
|
||||||
} else if (stream->avail_out >= 8) {
|
} else if (stream->avail_out >= 8) {
|
||||||
set_buf(bitbuf, stream->next_out, stream->avail_out);
|
set_buf(bitbuf, stream->next_out, stream->avail_out);
|
||||||
write_bits(bitbuf, stream->internal_state.has_eob_hdr, 3);
|
write_bits_flush(bitbuf, stream->internal_state.has_eob_hdr, 3);
|
||||||
flush(bitbuf);
|
|
||||||
stream->next_out = buffer_ptr(bitbuf);
|
stream->next_out = buffer_ptr(bitbuf);
|
||||||
stream->total_out += buffer_used(bitbuf);
|
stream->total_out += buffer_used(bitbuf);
|
||||||
stream->avail_out -= buffer_used(bitbuf);
|
stream->avail_out -= buffer_used(bitbuf);
|
||||||
|
Loading…
Reference in New Issue
Block a user