Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
Grpc
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
tci-gateway-module
Grpc
Commits
e9fa3114
Commit
e9fa3114
authored
9 years ago
by
David Garcia Quintas
Browse files
Options
Downloads
Patches
Plain Diff
Further coverage for compression
parent
3ff5d2dd
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/core/compression/message_compress.c
+2
-8
2 additions, 8 deletions
src/core/compression/message_compress.c
test/core/compression/message_compress_test.c
+34
-6
34 additions, 6 deletions
test/core/compression/message_compress_test.c
with
36 additions
and
14 deletions
src/core/compression/message_compress.c
+
2
−
8
View file @
e9fa3114
...
...
@@ -111,10 +111,7 @@ static int zlib_compress(gpr_slice_buffer* input, gpr_slice_buffer* output,
zs
.
zfree
=
zfree_gpr
;
r
=
deflateInit2
(
&
zs
,
Z_DEFAULT_COMPRESSION
,
Z_DEFLATED
,
15
|
(
gzip
?
16
:
0
),
8
,
Z_DEFAULT_STRATEGY
);
if
(
r
!=
Z_OK
)
{
gpr_log
(
GPR_ERROR
,
"deflateInit2 returns %d"
,
r
);
return
0
;
}
GPR_ASSERT
(
r
==
Z_OK
);
r
=
zlib_body
(
&
zs
,
input
,
output
,
deflate
)
&&
output
->
length
<
input
->
length
;
if
(
!
r
)
{
for
(
i
=
count_before
;
i
<
output
->
count
;
i
++
)
{
...
...
@@ -138,10 +135,7 @@ static int zlib_decompress(gpr_slice_buffer* input, gpr_slice_buffer* output,
zs
.
zalloc
=
zalloc_gpr
;
zs
.
zfree
=
zfree_gpr
;
r
=
inflateInit2
(
&
zs
,
15
|
(
gzip
?
16
:
0
));
if
(
r
!=
Z_OK
)
{
gpr_log
(
GPR_ERROR
,
"inflateInit2 returns %d"
,
r
);
return
0
;
}
GPR_ASSERT
(
r
==
Z_OK
);
r
=
zlib_body
(
&
zs
,
input
,
output
,
inflate
);
if
(
!
r
)
{
for
(
i
=
count_before
;
i
<
output
->
count
;
i
++
)
{
...
...
This diff is collapsed.
Click to expand it.
test/core/compression/message_compress_test.c
+
34
−
6
View file @
e9fa3114
...
...
@@ -148,26 +148,53 @@ static gpr_slice create_test_value(test_value id) {
return
gpr_slice_from_copied_string
(
"bad value"
);
}
static
void
test_
bad
_data
(
void
)
{
static
void
test_
tiny
_data
_compress
(
void
)
{
gpr_slice_buffer
input
;
gpr_slice_buffer
output
;
grpc_compression_algorithm
i
;
gpr_slice_buffer_init
(
&
input
);
gpr_slice_buffer_init
(
&
output
);
gpr_slice_buffer_add
(
&
input
,
gpr_slice_from_copied_string
(
"this is not valid compressed input"
));
gpr_slice_buffer_add
(
&
input
,
create_test_value
(
ONE_A
));
for
(
i
=
0
;
i
<
GRPC_COMPRESS_ALGORITHMS_COUNT
;
i
++
)
{
if
(
i
==
GRPC_COMPRESS_NONE
)
continue
;
GPR_ASSERT
(
0
==
grpc_msg_
de
compress
(
i
,
&
input
,
&
output
));
GPR_ASSERT
(
0
==
output
.
count
);
GPR_ASSERT
(
0
==
grpc_msg_compress
(
i
,
&
input
,
&
output
));
GPR_ASSERT
(
1
==
output
.
count
);
}
gpr_slice_buffer_destroy
(
&
input
);
gpr_slice_buffer_destroy
(
&
output
);
}
static
void
test_bad_data_decompress
(
void
)
{
gpr_slice_buffer
input
;
gpr_slice_buffer
corrupted
;
gpr_slice_buffer
output
;
size_t
idx
;
const
gpr_uint32
bad
=
0xdeadbeef
;
gpr_slice_buffer_init
(
&
input
);
gpr_slice_buffer_init
(
&
corrupted
);
gpr_slice_buffer_init
(
&
output
);
gpr_slice_buffer_add
(
&
input
,
create_test_value
(
ONE_MB_A
));
/* compress it */
grpc_msg_compress
(
GRPC_COMPRESS_GZIP
,
&
input
,
&
corrupted
);
/* corrupt the output by smashing the CRC */
GPR_ASSERT
(
corrupted
.
count
>
1
);
GPR_ASSERT
(
GPR_SLICE_LENGTH
(
corrupted
.
slices
[
1
])
>
8
);
idx
=
GPR_SLICE_LENGTH
(
corrupted
.
slices
[
1
])
-
8
;
memcpy
(
GPR_SLICE_START_PTR
(
corrupted
.
slices
[
1
])
+
idx
,
&
bad
,
4
);
/* try (and fail) to decompress the corrupted compresed buffer */
GPR_ASSERT
(
0
==
grpc_msg_decompress
(
GRPC_COMPRESS_GZIP
,
&
corrupted
,
&
output
));
gpr_slice_buffer_destroy
(
&
input
);
gpr_slice_buffer_destroy
(
&
corrupted
);
gpr_slice_buffer_destroy
(
&
output
);
}
static
void
test_bad_compression_algorithm
(
void
)
{
gpr_slice_buffer
input
;
gpr_slice_buffer
output
;
...
...
@@ -234,7 +261,8 @@ int main(int argc, char **argv) {
}
}
test_bad_data
();
test_tiny_data_compress
();
test_bad_data_decompress
();
test_bad_compression_algorithm
();
test_bad_decompression_algorithm
();
grpc_shutdown
();
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment