Skip to content

Commit 1b713e3

Browse files
committed
patch openappsec attachment to use zlib-ng
1 parent c0c4f74 commit 1b713e3

1 file changed

Lines changed: 89 additions & 2 deletions

File tree

nginx/attachment.patch

Lines changed: 89 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
diff --git a/CMakeLists.txt b/CMakeLists.txt
2-
index 745f969..88abd76 100644
2+
index ecdcb61..250e5ca 100644
33
--- a/CMakeLists.txt
44
+++ b/CMakeLists.txt
55
@@ -1,4 +1,4 @@
@@ -8,7 +8,7 @@ index 745f969..88abd76 100644
88
project(ngen)
99

1010
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC -Wno-terminate")
11-
@@ -10,5 +10,5 @@ include_directories(core/include/attachments)
11+
@@ -17,5 +17,5 @@ include_directories(core/include/attachments)
1212

1313
add_subdirectory(core)
1414
add_subdirectory(attachments)
@@ -89,3 +89,90 @@ index 8285065..19cdc99 100644
8989
+#add_subdirectory(shmem_ipc_2)
9090
add_subdirectory(compression)
9191
add_subdirectory(attachments)
92+
diff --git a/core/compression/compression_utils.cc b/core/compression/compression_utils.cc
93+
index c7e8922..f0f5930 100644
94+
--- a/core/compression/compression_utils.cc
95+
+++ b/core/compression/compression_utils.cc
96+
@@ -21,7 +21,7 @@
97+
#include <tuple>
98+
#include <strings.h>
99+
#include <string.h>
100+
-#include <zlib.h>
101+
+#include <zlib-ng.h>
102+
#include <brotli/encode.h>
103+
#include <brotli/decode.h>
104+
105+
@@ -115,7 +115,7 @@ struct CompressionStream
106+
br_encoder_state(nullptr),
107+
br_decoder_state(nullptr)
108+
{
109+
- bzero(&stream, sizeof(z_stream));
110+
+ bzero(&stream, sizeof(zng_stream));
111+
}
112+
113+
~CompressionStream() { fini(); }
114+
@@ -144,7 +144,7 @@ struct CompressionStream
115+
116+
auto old_total_out = stream.total_out;
117+
118+
- auto inflate_res = inflate(&stream, zlib_no_flush);
119+
+ auto inflate_res = zng_inflate(&stream, zlib_no_flush);
120+
121+
if (inflate_res != Z_OK && inflate_res != Z_STREAM_END) {
122+
fini();
123+
@@ -181,7 +181,7 @@ struct CompressionStream
124+
stream.next_in = data;
125+
126+
vector<unsigned char> work_space;
127+
- work_space.reserve(deflateBound(&stream, stream.avail_in));
128+
+ work_space.reserve(zng_deflateBound(&stream, stream.avail_in));
129+
basic_string<unsigned char> res;
130+
int retries = 0;
131+
132+
@@ -191,7 +191,7 @@ struct CompressionStream
133+
134+
auto old_total_out = stream.total_out;
135+
136+
- int deflate_res = deflate(&stream, is_last_chunk ? zlib_finish_flush : zlib_sync_flush);
137+
+ int deflate_res = zng_deflate(&stream, is_last_chunk ? zlib_finish_flush : zlib_sync_flush);
138+
139+
if (deflate_res != Z_OK && deflate_res != Z_STREAM_END) {
140+
fini();
141+
@@ -221,7 +221,7 @@ private:
142+
{
143+
if (state != TYPE::UNINITIALIZED) return;
144+
145+
- auto init_status = inflateInit2(&stream, default_num_window_bits + 32);
146+
+ auto init_status = zng_inflateInit2(&stream, default_num_window_bits + 32);
147+
if (init_status != zlib_ok_return_value) {
148+
throw runtime_error(
149+
"Failed to initialize decompression stream. Error: " + getZlibError(init_status)
150+
@@ -258,7 +258,7 @@ private:
151+
}
152+
}
153+
154+
- int init_status = deflateInit2(
155+
+ int init_status = zng_deflateInit2(
156+
&stream,
157+
default_compression_level,
158+
default_compression_method,
159+
@@ -464,8 +464,8 @@ private:
160+
{
161+
int end_stream_res = zlib_ok_return_value;
162+
163+
- if (state == TYPE::DECOMPRESS) end_stream_res = inflateEnd(&stream);
164+
- if (state == TYPE::COMPRESS) end_stream_res = deflateEnd(&stream);
165+
+ if (state == TYPE::DECOMPRESS) end_stream_res = zng_inflateEnd(&stream);
166+
+ if (state == TYPE::COMPRESS) end_stream_res = zng_deflateEnd(&stream);
167+
168+
if (br_encoder_state) {
169+
BrotliEncoderDestroyInstance(br_encoder_state);
170+
@@ -503,7 +503,7 @@ private:
171+
}
172+
}
173+
174+
- z_stream stream;
175+
+ zng_stream stream;
176+
enum class TYPE {
177+
UNINITIALIZED,
178+
COMPRESS,

0 commit comments

Comments
 (0)