1 /**
2  * Copyright (C) 2023 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include <binder/Parcel.h>
18 #include <sensor/Sensor.h>
19 
20 #include <fstream>
21 
22 #include "../includes/common.h"
23 #include "../includes/memutils.h"
24 
25 using namespace android;
26 using namespace std;
27 
28 char enable_selective_overload = ENABLE_NONE;
29 
fillParcel(Parcel & reply)30 void fillParcel(Parcel &reply) {
31   ifstream inputFile("cve_2023_21118.bin", ios::binary);
32   FAIL_CHECK(inputFile.is_open());
33 
34   // Compute size of file
35   inputFile.seekg(0, std::ios::end);
36   std::streampos fileSize = inputFile.tellg();
37   inputFile.seekg(0, std::ios::beg);
38 
39   // Fill parcel with file data
40   vector<uint8_t> fileData(fileSize);
41   inputFile.read(reinterpret_cast<char *>(fileData.data()), fileSize);
42   inputFile.close();
43   reply.write(fileData.data(), fileSize);
44   reply.setDataPosition(25044 /* Set data position to required position */);
45 }
46 
main()47 int main() {
48   Parcel reply;
49   Sensor s;
50   fillParcel(reply);
51   enable_selective_overload = ENABLE_ALL;
52   reply.read(s);
53   enable_selective_overload = ENABLE_FREE_CHECK | ENABLE_REALLOC_CHECK;
54   return 0;
55 }
56