From 335b7242099153f0777ce5417b8ef8261de03ec8 Mon Sep 17 00:00:00 2001 From: Jeroen van Rijn Date: Sun, 1 May 2022 12:47:05 +0200 Subject: [PATCH] [xxh3] Fix flaws in streaming implementation --- core/hash/xxhash/streaming.odin | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/core/hash/xxhash/streaming.odin b/core/hash/xxhash/streaming.odin index d6df1089f..68a4920a5 100644 --- a/core/hash/xxhash/streaming.odin +++ b/core/hash/xxhash/streaming.odin @@ -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 @@ -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 } @@ -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(