Skip to content

Commit

Permalink
Merge pull request #1760 from Kelimion/xxh3_fix
Browse files Browse the repository at this point in the history
[xxh3] Fix flaws in streaming implementation
  • Loading branch information
Kelimion committed May 1, 2022
2 parents 6ade9ac + 335b724 commit df233ae
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions core/hash/xxhash/streaming.odin
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,6 @@ XXH3_128_reset_with_seed :: proc(state: ^XXH3_state, seed: XXH64_hash) -> (err:
XXH3_64_reset_with_seed :: XXH3_128_reset_with_seed

XXH3_128_update :: proc(state: ^XXH3_state, input: []u8) -> (err: Error) {
if len(input) < XXH3_MIDSIZE_MAX {
return .Error
}
return XXH3_update(state, input, XXH3_accumulate_512, XXH3_scramble_accumulator)
}
XXH3_64_update :: XXH3_128_update
Expand Down Expand Up @@ -127,6 +124,7 @@ XXH3_create_state :: proc(allocator := context.allocator) -> (res: ^XXH3_state,
err = nil if mem_error == nil else .Error

XXH3_init_state(state)
XXH3_128_reset(state)
return state, nil
}

Expand Down Expand Up @@ -234,7 +232,9 @@ XXH3_update :: #force_inline proc(
*/
if state.buffered_size > 0 {
load_size := int(XXH3_INTERNAL_BUFFER_SIZE - state.buffered_size)
mem_copy(&state.buffer[state.buffered_size], &input[0], load_size)

state_ptr := rawptr(uintptr(raw_data(state.buffer[:])) + uintptr(state.buffered_size))
mem_copy(state_ptr, raw_data(input), load_size)
input = input[load_size:]

XXH3_consume_stripes(
Expand Down

0 comments on commit df233ae

Please sign in to comment.