Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 20 additions & 6 deletions .github/workflows/build_and_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,30 @@ jobs:
sudo ln -sf /usr/local/bin/ld /usr/bin/lld
- name: Configure CMake
run: |
cmake . -DHPACK_ENABLE_TESTING=ON \
-DCMAKE_BUILD_TYPE=${{matrix.build_type}} \
-DCMAKE_CXX_COMPILER=${{matrix.compiler}} \
-DCMAKE_CXX_STANDARD=${{matrix.cpp_standard}} \
cmake . -DHPACK_ENABLE_TESTING=ON \
-DCMAKE_BUILD_TYPE=${{matrix.build_type}} \
-DCMAKE_CXX_COMPILER=${{matrix.compiler}} \
-DCMAKE_CXX_STANDARD=${{matrix.cpp_standard}} \
-B build -G "Ninja"
- name: Build
run:
cmake --build build

- name: Test
run: |
cd build
ctest --output-on-failure -C ${{matrix.build_type}} -V
ctest --output-on-failure -C ${{matrix.build_type}}
- name: Configure CMake sanitizers
run: |
cmake . -DHPACK_ENABLE_TESTING=ON \
-DCMAKE_BUILD_TYPE=${{matrix.build_type}} \
-DCMAKE_CXX_COMPILER=${{matrix.compiler}} \
-DCMAKE_CXX_STANDARD=${{matrix.cpp_standard}} \
-DHPACK_ENABLE_SANITIZERS=ON \
-B build_sanitizers -G "Ninja"
- name: Build
run:
cmake --build build_sanitizers
- name: Test sanitizers
run: |
cd build_sanitizers
ctest --output-on-failure -C ${{matrix.build_type}}
10 changes: 10 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,16 @@ project(HPACK LANGUAGES CXX)

option(HPACK_ENABLE_TESTING "enables testing" OFF)
option(HPACK_USE_CPM "turn off to not download boost" ON)
option(HPACK_ENABLE_SANITIZERS "enables tests with sanitizers. Ignored if HPACK_ENABLE_TESTING == 0" OFF)

if (HPACK_ENABLE_SANITIZERS)
# enable sanitize flags globally, all targets require to be compiled with them

# fno omit frame pointer to improve trace from sanitizers
add_compile_options(-fsanitize=address -fsanitize=undefined -fno-omit-frame-pointer)
add_link_options(-fsanitize=address -fsanitize=undefined)

endif()

### dependecies ###

Expand Down
2 changes: 1 addition & 1 deletion include/hpack/basic_types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ struct sym_info_t {
uint32_t bits;
uint8_t bit_count;
};
extern const sym_info_t huffman_table[257];
sym_info_t huffman_table_get(uint8_t index) noexcept;

// uint16_t(-1) if not found
uint16_t huffman_decode_table_find(sym_info_t info);
Expand Down
4 changes: 2 additions & 2 deletions include/hpack/strings.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ O encode_string_huffman(std::string_view str, O _out) {
// (size should be before string and len in bits depends on 'len' value)
size_type len_after_encode = 0;
for (char c : str)
len_after_encode += huffman_table[uint8_t(c)].bit_count;
len_after_encode += huffman_table_get(uint8_t(c)).bit_count;
*out = 0b1000'0000; // set H bit
// % 8 for guarantee, that padding ALWAYS < 7 bits. Its makes no sense to add entire byte or more padding
// https://datatracker.ietf.org/doc/html/rfc7541#section-5.2
Expand All @@ -33,7 +33,7 @@ O encode_string_huffman(std::string_view str, O _out) {
}
};
for (char c : str) {
sym_info_t bits = huffman_table[uint8_t(c)];
sym_info_t bits = huffman_table_get(uint8_t(c));
for (int i = 0; i < bits.bit_count; ++i)
push_bit(bits.bits & (1 << i));
}
Expand Down
3 changes: 0 additions & 3 deletions src/decoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@ namespace hpack {
return size_t(huffman_str_len) * 8 / 5;
}

// uint16_t(-1) if not found
uint16_t huffman_decode_table_find(sym_info_t info);

// precondition: in != e
// note: 'len' must be decoded before calling this function
template <Out O>
Expand Down
4 changes: 4 additions & 0 deletions src/huffman.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ constexpr sym_info_t huffman_table[257] = {
#include "hpack/huffman_table.def"
};

sym_info_t huffman_table_get(uint8_t i) noexcept {
return huffman_table[i];
}

uint16_t huffman_decode_table_find(sym_info_t info) {
#define HUFFMAN_TABLE(index, bits, bitcount) \
case bits: \
Expand Down