-
Notifications
You must be signed in to change notification settings - Fork 137
Fix: Check flatbuffer integrity before parsing #1864
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
dab06ad
414623b
dbc0e3d
05be663
5bae82d
116f593
efcb905
1d40290
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -14,6 +14,9 @@ | |||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| #include "remote_config/src/desktop/metadata.h" | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| #include <cerrno> | ||||||||||||||||||||||||||||||||||||||||
| #include <cstdlib> | ||||||||||||||||||||||||||||||||||||||||
| #include <limits> | ||||||||||||||||||||||||||||||||||||||||
| #include <map> | ||||||||||||||||||||||||||||||||||||||||
| #include <string> | ||||||||||||||||||||||||||||||||||||||||
|
AustinBenoit marked this conversation as resolved.
|
||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
|
|
@@ -58,6 +61,9 @@ std::string RemoteConfigMetadata::Serialize() const { | |||||||||||||||||||||||||||||||||||||||
| void RemoteConfigMetadata::Deserialize(const std::string& buffer) { | ||||||||||||||||||||||||||||||||||||||||
| const uint8_t* data = reinterpret_cast<const uint8_t*>(buffer.data()); | ||||||||||||||||||||||||||||||||||||||||
| size_t size = buffer.size(); | ||||||||||||||||||||||||||||||||||||||||
| if (!flexbuffers::VerifyBuffer(data, size)) { | ||||||||||||||||||||||||||||||||||||||||
| return; | ||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
| auto struct_map = flexbuffers::GetRoot(data, size).AsMap(); | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| flexbuffers::Map info = struct_map["info"].AsMap(); | ||||||||||||||||||||||||||||||||||||||||
|
|
@@ -75,7 +81,18 @@ void RemoteConfigMetadata::Deserialize(const std::string& buffer) { | |||||||||||||||||||||||||||||||||||||||
| settings_.clear(); | ||||||||||||||||||||||||||||||||||||||||
| flexbuffers::Map settings = struct_map["settings"].AsMap(); | ||||||||||||||||||||||||||||||||||||||||
| for (int i = 0, n = settings.size(); i < n; ++i) { | ||||||||||||||||||||||||||||||||||||||||
| int int_key = std::stoi(settings.Keys()[i].AsKey()); | ||||||||||||||||||||||||||||||||||||||||
| const char* key_str = settings.Keys()[i].AsKey(); | ||||||||||||||||||||||||||||||||||||||||
| if (!key_str) continue; | ||||||||||||||||||||||||||||||||||||||||
| char* endptr = nullptr; | ||||||||||||||||||||||||||||||||||||||||
| long raw_key = std::strtol(key_str, &endptr, 10); | ||||||||||||||||||||||||||||||||||||||||
| if (endptr == key_str || *endptr != '\0') { | ||||||||||||||||||||||||||||||||||||||||
| continue; | ||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
| if (raw_key < std::numeric_limits<int>::min() || | ||||||||||||||||||||||||||||||||||||||||
| raw_key > std::numeric_limits<int>::max()) { | ||||||||||||||||||||||||||||||||||||||||
| continue; | ||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+86
to
+94
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On platforms where To correctly detect overflow on all platforms, you should clear
Suggested change
|
||||||||||||||||||||||||||||||||||||||||
| int int_key = static_cast<int>(raw_key); | ||||||||||||||||||||||||||||||||||||||||
| settings_[static_cast<ConfigSetting>(int_key)] = | ||||||||||||||||||||||||||||||||||||||||
| settings.Values()[i].AsString().c_str(); | ||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| From: Antigravity <antigravity@google.com> | ||
| Subject: Patch flatbuffers to resolve ERROR macro conflict on Windows | ||
|
|
||
| Workaround for conflict between ProtoIdGapAction::ERROR in idl.h and the | ||
| Windows global ERROR macro defined in wingdi.h/windows.h. | ||
|
|
||
| See Flatbuffers Issue: https://github.com/google/flatbuffers/issues/8483 | ||
|
|
||
| diff --git a/include/flatbuffers/idl.h b/include/flatbuffers/idl.h | ||
| index 95fda8c2..6da1c6e3 100644 | ||
| --- a/include/flatbuffers/idl.h | ||
| +++ b/include/flatbuffers/idl.h | ||
| @@ -17,6 +17,12 @@ | ||
| #ifndef FLATBUFFERS_IDL_H_ | ||
| #define FLATBUFFERS_IDL_H_ | ||
|
|
||
| +#ifdef ERROR | ||
| +#pragma push_macro("ERROR") | ||
| +#undef ERROR | ||
| +#define FLATBUFFERS_POP_ERROR_MACRO | ||
| +#endif | ||
| + | ||
| #include <algorithm> | ||
| #include <functional> | ||
| #include <map> | ||
| @@ -1325,4 +1331,9 @@ extern bool GenerateTSGRPC(const Parser& parser, const std::string& path, | ||
| const std::string& file_name); | ||
| } // namespace flatbuffers | ||
|
|
||
| +#ifdef FLATBUFFERS_POP_ERROR_MACRO | ||
| +#pragma pop_macro("ERROR") | ||
| +#undef FLATBUFFERS_POP_ERROR_MACRO | ||
| +#endif | ||
| + | ||
| #endif // FLATBUFFERS_IDL_H_ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If
app.options().package_name()returnsnullptr, constructing astd::stringdirectly from it will result in undefined behavior (typically a crash). It is safer to perform a null check before constructing the string.