mirror of
https://github.com/firebase/firebase-ios-sdk
synced 2026-11-10 22:45:59 +05:45
* Use nanopb::Reader, Writer, in the serializer's public methods. This eliminates overloads that take raw bytes.
* Refactor the serializer's return values from Status, StatusOr<T> to void, optional<T> (or unique_ptr<T>) for encoding/decode methods, respectively.
* Errors during serializer encoding methods now fatal. Previously, we'd propagate the errors back to the caller, but there aren't any errors that could realistically be recovered from. So now we just abort(). (This is in contrast to *de*coding methods, which could generate errors that we might want to recover from.)
* Reduce early returns in the serializers
* Unify public/private method return values of the serializers. Now the private methods return void/optional, just like the public methods.
* Reader::ReadTag now tracks the last read tag. This allows:
* RequireWireType to not need it as a parameter
* SkipField to not need it as a parameter
* ReadTag to be inlined into most switch statements
* Move RequireWireType into ReadX methods
* Reader::SkipField -> Reader::SkipUnknown
* Add ReadNestedMessage overload in order to accept non-static functions.
* Add a few using statements to simplify code. (Also keeps local serializer more in sync with the remote serializer.)
* Use nullopt/nullptr instead of {}
* Reader::update_status() -> Fail()
* Add DecodeSnapshotVersion
* Don't directly update status within nanopb::Reader. Instead, call Reader::Fail() (which calls Status::Update()). This ensures we don't accidentally overwrite the first error status with
a subsequent one.
55 lines
1.7 KiB
Plaintext
55 lines
1.7 KiB
Plaintext
/*
|
|
* Copyright 2018 Google
|
|
*
|
|
* 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.
|
|
*/
|
|
|
|
#import <Foundation/Foundation.h>
|
|
#include <cstddef>
|
|
#include <cstdint>
|
|
|
|
#import "Firestore/Example/FuzzTests/FuzzingTargets/FSTFuzzTestSerializer.h"
|
|
|
|
#include "Firestore/core/src/firebase/firestore/model/database_id.h"
|
|
#include "Firestore/core/src/firebase/firestore/nanopb/reader.h"
|
|
#include "Firestore/core/src/firebase/firestore/remote/serializer.h"
|
|
|
|
namespace firebase {
|
|
namespace firestore {
|
|
namespace fuzzing {
|
|
|
|
using firebase::firestore::model::DatabaseId;
|
|
using firebase::firestore::nanopb::Reader;
|
|
using firebase::firestore::remote::Serializer;
|
|
|
|
int FuzzTestDeserialization(const uint8_t *data, size_t size) {
|
|
Serializer serializer{DatabaseId{"project", DatabaseId::kDefault}};
|
|
|
|
@autoreleasepool {
|
|
@try {
|
|
Reader reader = Reader::Wrap(data, size);
|
|
serializer.DecodeFieldValue(&reader);
|
|
} @catch (...) {
|
|
// Caught exceptions are ignored because the input might be malformed and
|
|
// the deserialization might throw an error as intended. Fuzzing focuses on
|
|
// runtime errors that are detected by the sanitizers.
|
|
}
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
} // namespace fuzzing
|
|
} // namespace firestore
|
|
} // namespace firebase
|