igzip: Use full 32 bits histogram elements in igizp_icf_body/finish

This fix prevents possible histogram overflow in compression.

Change-Id: Ie5f25d1bace7f443f432678fcfbd9050ac65113f
Signed-off-by: Roy Oursler <roy.j.oursler@intel.com>
This commit is contained in:
Roy Oursler 2017-12-15 13:06:13 -07:00
parent 8965584ae3
commit 5d413c8b12
2 changed files with 12 additions and 12 deletions

View File

@ -283,7 +283,7 @@ isal_deflate_icf_body_ %+ METHOD %+ _ %+ ARCH %+ :
test len %+ d, 0xFFFFFFFF test len %+ d, 0xFFFFFFFF
jz .len_dist_huffman_pre jz .len_dist_huffman_pre
inc word [lit_len_hist + HIST_ELEM_SIZE*lit_code] inc dword [lit_len_hist + HIST_ELEM_SIZE*lit_code]
movzx lit_code2, curr_data %+ b movzx lit_code2, curr_data %+ b
;; Check for len/dist match for second literal ;; Check for len/dist match for second literal
test len2 %+ d, 0xFFFFFFFF test len2 %+ d, 0xFFFFFFFF
@ -333,14 +333,14 @@ isal_deflate_icf_body_ %+ METHOD %+ _ %+ ARCH %+ :
add dist_code2, 254 add dist_code2, 254
add dist_code2, len2 add dist_code2, len2
inc word [lit_len_hist + HIST_ELEM_SIZE*(len2 + 254)] inc dword [lit_len_hist + HIST_ELEM_SIZE*(len2 + 254)]
movnti dword [m_out_buf + 4], dist_code2 %+ d movnti dword [m_out_buf + 4], dist_code2 %+ d
add m_out_buf, 8 add m_out_buf, 8
shr dist_code2, DIST_OFFSET shr dist_code2, DIST_OFFSET
and dist_code2, 0x1F and dist_code2, 0x1F
inc word [dist_hist + HIST_ELEM_SIZE*dist_code2] inc dword [dist_hist + HIST_ELEM_SIZE*dist_code2]
; hash = compute_hash(state->file_start + f_i) & HASH_MASK; ; hash = compute_hash(state->file_start + f_i) & HASH_MASK;
and hash %+ d, HASH_MASK and hash %+ d, HASH_MASK
@ -385,14 +385,14 @@ isal_deflate_icf_body_ %+ METHOD %+ _ %+ ARCH %+ :
shr curr_data2, 8 shr curr_data2, 8
compute_hash hash2, curr_data2 compute_hash hash2, curr_data2
inc word [lit_len_hist + HIST_ELEM_SIZE*len_code] inc dword [lit_len_hist + HIST_ELEM_SIZE*len_code]
movnti dword [m_out_buf], dist_code %+ d movnti dword [m_out_buf], dist_code %+ d
add m_out_buf, 4 add m_out_buf, 4
shr dist_code, DIST_OFFSET shr dist_code, DIST_OFFSET
and dist_code, 0x1F and dist_code, 0x1F
inc word [dist_hist + HIST_ELEM_SIZE*dist_code] inc dword [dist_hist + HIST_ELEM_SIZE*dist_code]
; hash = compute_hash(state->file_start + f_i) & HASH_MASK; ; hash = compute_hash(state->file_start + f_i) & HASH_MASK;
and hash %+ d, HASH_MASK and hash %+ d, HASH_MASK
@ -408,7 +408,7 @@ isal_deflate_icf_body_ %+ METHOD %+ _ %+ ARCH %+ :
add f_i, 1 add f_i, 1
MOVQ curr_data, xdata MOVQ curr_data, xdata
inc word [lit_len_hist + HIST_ELEM_SIZE*lit_code2] inc dword [lit_len_hist + HIST_ELEM_SIZE*lit_code2]
shl lit_code2, DIST_OFFSET shl lit_code2, DIST_OFFSET
lea lit_code, [lit_code + lit_code2 + (31 << DIST_OFFSET)] lea lit_code, [lit_code + lit_code2 + (31 << DIST_OFFSET)]
@ -497,7 +497,7 @@ isal_deflate_icf_body_ %+ METHOD %+ _ %+ ARCH %+ :
%endif %endif
movzx lit_code, curr_data %+ b movzx lit_code, curr_data %+ b
shr curr_data, 8 shr curr_data, 8
inc word [lit_len_hist + HIST_ELEM_SIZE*lit_code] inc dword [lit_len_hist + HIST_ELEM_SIZE*lit_code]
jmp .len_dist_lit_huffman jmp .len_dist_lit_huffman
.write_first_byte: .write_first_byte:
@ -513,7 +513,7 @@ isal_deflate_icf_body_ %+ METHOD %+ _ %+ ARCH %+ :
compute_hash hash2, tmp2 compute_hash hash2, tmp2
and curr_data, 0xff and curr_data, 0xff
inc word [lit_len_hist + HIST_ELEM_SIZE*curr_data] inc dword [lit_len_hist + HIST_ELEM_SIZE*curr_data]
or curr_data, LIT or curr_data, LIT
movnti dword [m_out_buf], curr_data %+ d movnti dword [m_out_buf], curr_data %+ d

View File

@ -206,7 +206,7 @@ isal_deflate_icf_finish_ %+ METHOD %+ _01:
lea code, [len + 254] lea code, [len + 254]
or code2, code or code2, code
inc word [lit_len_hist + HIST_ELEM_SIZE*code] inc dword [lit_len_hist + HIST_ELEM_SIZE*code]
; for (k = f_i+1, f_i += len-1; k <= f_i; k++) { ; for (k = f_i+1, f_i += len-1; k <= f_i; k++) {
lea tmp3, [f_i + 1] ; tmp3 <= k lea tmp3, [f_i + 1] ; tmp3 <= k
@ -236,7 +236,7 @@ isal_deflate_icf_finish_ %+ METHOD %+ _01:
write_dword code2, m_out_buf write_dword code2, m_out_buf
shr code2, DIST_OFFSET shr code2, DIST_OFFSET
and code2, 0x1F and code2, 0x1F
inc word [dist_hist + HIST_ELEM_SIZE*code2] inc dword [dist_hist + HIST_ELEM_SIZE*code2]
; continue ; continue
cmp f_i, [rsp + f_end_i_mem_offset] cmp f_i, [rsp + f_end_i_mem_offset]
jl .loop2 jl .loop2
@ -245,7 +245,7 @@ isal_deflate_icf_finish_ %+ METHOD %+ _01:
.encode_literal: .encode_literal:
; get_lit_code(state->file_start[f_i], &code2, &code_len2); ; get_lit_code(state->file_start[f_i], &code2, &code_len2);
movzx tmp5, byte [file_start + f_i] movzx tmp5, byte [file_start + f_i]
inc word [lit_len_hist + HIST_ELEM_SIZE*tmp5] inc dword [lit_len_hist + HIST_ELEM_SIZE*tmp5]
or tmp5, LIT or tmp5, LIT
write_dword tmp5, m_out_buf write_dword tmp5, m_out_buf
; continue ; continue
@ -267,7 +267,7 @@ isal_deflate_icf_finish_ %+ METHOD %+ _01:
ja .out_end ja .out_end
movzx tmp5, byte [file_start + f_i] movzx tmp5, byte [file_start + f_i]
inc word [lit_len_hist + HIST_ELEM_SIZE*tmp5] inc dword [lit_len_hist + HIST_ELEM_SIZE*tmp5]
or tmp5, LIT or tmp5, LIT
write_dword tmp5, m_out_buf write_dword tmp5, m_out_buf