Permalink
Show file tree
Hide file tree
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Throw on bad types during skipping data
Summary: The current code silently returns on bad types. In case when we have an invalid data, we may get a container of a large size with a bad type, this would lead to us running long loop doing nothing (though we already can say that the data is invalid). The new code would throw an exception as soon as we try to skip a value of invalid type. Fixes CVE-2019-3552 Reviewed By: yfeldblum, stevegury Differential Revision: D8344920 fbshipit-source-id: f12e8f3442f7ad5e1a81d822380701e929b80f0d
- Loading branch information
1 parent
c595188
commit c5d6e07
Showing
5 changed files
with
87 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| /* | ||
| * Copyright 2004-present Facebook, Inc. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| #include <gtest/gtest.h> | ||
|
|
||
| #include <thrift/lib/cpp2/protocol/CompactProtocol.h> | ||
|
|
||
| using namespace apache::thrift; | ||
|
|
||
| TEST(ProtocolSkipTest, SkipInt) { | ||
| IOBufQueue queue; | ||
| CompactProtocolWriter writer; | ||
| writer.setOutput(&queue); | ||
| writer.writeI32(123); | ||
| auto buf = queue.move(); | ||
| CompactProtocolReader reader; | ||
| reader.setInput(buf.get()); | ||
| reader.skip(TType::T_I32); | ||
| } | ||
|
|
||
| TEST(ProtocolSkipTest, SkipStop) { | ||
| IOBufQueue queue; | ||
| CompactProtocolWriter writer; | ||
| writer.setOutput(&queue); | ||
| writer.writeFieldStop(); | ||
| auto buf = queue.move(); | ||
| CompactProtocolReader reader; | ||
| reader.setInput(buf.get()); | ||
| bool thrown = false; | ||
| try { | ||
| reader.skip(TType::T_STOP); | ||
| } catch (const TProtocolException& ex) { | ||
| EXPECT_EQ(TProtocolException::INVALID_DATA, ex.getType()); | ||
| thrown = true; | ||
| } | ||
| EXPECT_TRUE(thrown); | ||
| } | ||
|
|
||
| TEST(ProtocolSkipTest, SkipStopInContainer) { | ||
| IOBufQueue queue; | ||
| CompactProtocolWriter writer; | ||
| writer.setOutput(&queue); | ||
| writer.writeListBegin(TType::T_STOP, 1u << 30); | ||
| auto buf = queue.move(); | ||
| CompactProtocolReader reader; | ||
| reader.setInput(buf.get()); | ||
| bool thrown = false; | ||
| try { | ||
| reader.skip(TType::T_LIST); | ||
| } catch (const TProtocolException& ex) { | ||
| EXPECT_EQ(TProtocolException::INVALID_DATA, ex.getType()); | ||
| thrown = true; | ||
| } | ||
| EXPECT_TRUE(thrown); | ||
| } |