Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
Actor Framework
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Metrics
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
cpp-libs
Actor Framework
Commits
1fe2518f
Commit
1fe2518f
authored
Aug 11, 2023
by
Samir Halilcevic
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fail very eary on invalid UTF-8
parent
16b40d40
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
38 additions
and
1 deletion
+38
-1
libcaf_net/caf/net/web_socket/framing.cpp
libcaf_net/caf/net/web_socket/framing.cpp
+38
-1
No files found.
libcaf_net/caf/net/web_socket/framing.cpp
View file @
1fe2518f
...
@@ -106,7 +106,44 @@ ptrdiff_t framing::consume(byte_span buffer, byte_span) {
...
@@ -106,7 +106,44 @@ ptrdiff_t framing::consume(byte_span buffer, byte_span) {
// Wait for more data if necessary.
// Wait for more data if necessary.
size_t
frame_size
=
hdr_bytes
+
hdr
.
payload_len
;
size_t
frame_size
=
hdr_bytes
+
hdr
.
payload_len
;
if
(
buffer
.
size
()
<
frame_size
)
{
if
(
buffer
.
size
()
<
frame_size
)
{
// when handling a text frame we want to fail early on invalid UTF-8
if
(
hdr
.
opcode
==
detail
::
rfc6455
::
text_frame
||
opcode_
==
detail
::
rfc6455
::
text_frame
)
{
down_
->
configure_read
(
receive_policy
::
between
(
buffer
.
size
()
+
1
,
frame_size
));
if
(
hdr
.
opcode
==
detail
::
rfc6455
::
text_frame
)
{
auto
arrived_payload
=
std
::
vector
<
std
::
byte
>
{
buffer
.
begin
()
+
hdr_bytes
,
buffer
.
end
()};
if
(
hdr
.
mask_key
!=
0
)
{
detail
::
rfc6455
::
mask_data
(
hdr
.
mask_key
,
arrived_payload
);
}
if
(
auto
[
index
,
incomplete
]
=
detail
::
rfc3629
::
validate
(
arrived_payload
);
index
!=
arrived_payload
.
size
()
&&
!
incomplete
)
{
abort_and_shutdown
(
sec
::
malformed_message
,
"invalid UTF-8 sequence"
);
return
-
1
;
}
}
else
{
auto
unvalidated_payload
=
std
::
vector
<
std
::
byte
>
{
payload_buf_
.
begin
()
+
static_cast
<
ptrdiff_t
>
(
validation_offset_
),
payload_buf_
.
end
()};
unvalidated_payload
.
insert
(
unvalidated_payload
.
end
(),
buffer
.
begin
()
+
hdr_bytes
,
buffer
.
end
());
if
(
hdr
.
mask_key
!=
0
)
{
detail
::
rfc6455
::
mask_data
(
hdr
.
mask_key
,
make_span
(
unvalidated_payload
)
.
subspan
(
payload_buf_
.
size
()
-
validation_offset_
));
}
if
(
auto
[
index
,
incomplete
]
=
detail
::
rfc3629
::
validate
(
unvalidated_payload
);
index
!=
unvalidated_payload
.
size
()
&&
!
incomplete
)
{
abort_and_shutdown
(
sec
::
malformed_message
,
"invalid UTF-8 sequence"
);
return
-
1
;
}
}
}
else
{
down_
->
configure_read
(
receive_policy
::
exactly
(
frame_size
));
down_
->
configure_read
(
receive_policy
::
exactly
(
frame_size
));
}
return
0
;
return
0
;
}
}
// Decode frame.
// Decode frame.
...
...
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