Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
L
libzmq
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
libzmq
Commits
f497aae8
Commit
f497aae8
authored
Apr 30, 2012
by
Pieter Hintjens
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #333 from hurtonm/fix_decoder_to_properly_handle_large_messages
Fix decoder to properly handle large messages
parents
36bfaaab
5227f676
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
15 deletions
+24
-15
decoder.cpp
src/decoder.cpp
+24
-15
No files found.
src/decoder.cpp
View file @
f497aae8
...
...
@@ -21,6 +21,7 @@
#include <stdlib.h>
#include <string.h>
#include <limits>
#include "decoder.hpp"
#include "session_base.hpp"
...
...
@@ -96,33 +97,41 @@ bool zmq::decoder_t::one_byte_size_ready ()
bool
zmq
::
decoder_t
::
eight_byte_size_ready
()
{
// 8-byte
size is read. Allocate the buffer for message body and
// read the message data into it.
size_t
size
=
(
size_t
)
get_uint64
(
tmpbuf
);
// 8-byte
payload length is read. Allocate the buffer
//
for message body and
read the message data into it.
const
uint64_t
payload_length
=
get_uint64
(
tmpbuf
);
// There has to be at least one byte (the flags) in the message).
if
(
!
size
)
{
if
(
payload_length
==
0
)
{
decoding_error
();
return
false
;
}
// Message size must not exceed the maximum allowed size.
if
(
maxmsgsize
>=
0
&&
payload_length
-
1
>
(
uint64_t
)
maxmsgsize
)
{
decoding_error
();
return
false
;
}
// Message size must fit within range of size_t data type.
if
(
payload_length
-
1
>
std
::
numeric_limits
<
size_t
>::
max
())
{
decoding_error
();
return
false
;
}
const
size_t
msg_size
=
static_cast
<
size_t
>
(
payload_length
-
1
);
// in_progress is initialised at this point so in theory we should
// close it before calling
zmq_msg_
init_size, however, it's a 0-byte
// close it before calling init_size, however, it's a 0-byte
// message and thus we can treat it as uninitialised...
int
rc
;
if
(
maxmsgsize
>=
0
&&
(
int64_t
)
(
size
-
1
)
>
maxmsgsize
)
{
rc
=
-
1
;
errno
=
ENOMEM
;
}
else
rc
=
in_progress
.
init_size
(
size
-
1
);
if
(
rc
!=
0
&&
errno
==
ENOMEM
)
{
int
rc
=
in_progress
.
init_size
(
msg_size
);
if
(
rc
!=
0
)
{
errno_assert
(
errno
==
ENOMEM
);
rc
=
in_progress
.
init
();
errno_assert
(
rc
==
0
);
decoding_error
();
return
false
;
}
errno_assert
(
rc
==
0
);
next_step
(
tmpbuf
,
1
,
&
decoder_t
::
flags_ready
);
return
true
;
...
...
@@ -135,7 +144,7 @@ bool zmq::decoder_t::flags_ready ()
next_step
(
in_progress
.
data
(),
in_progress
.
size
(),
&
decoder_t
::
message_ready
);
return
true
;
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment