MCPcopy Create free account
hub / github.com/OpenBoardView/OpenBoardView / parse

Method parse

src/openboardview/FileFormats/FZFile.cpp:218–488  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

216}
217
218void FZFile::parse(std::vector<char> &buf, const std::array<uint32_t, 44> &fzkey) {
219 auto buffer_size = buf.size();
220 char *saved_locale;
221 float multiplier = 1.0f;
222 saved_locale = setlocale(LC_NUMERIC, "C"); // Use '.' as delimiter for strtod
223
224 if (check_fz_key(fzkey)) {
225 key = fzkey;
226 } else if (check_fz_key(getBuiltinKey())) { // Try to fallback to built-in key
227 key = getBuiltinKey();
228 } else {
229 valid = false;
230 error_msg = getKeyErrorMsg();
231 error_msg += fz_key_to_string(fzkey);
232 return;
233 }
234
235 ENSURE_OR_FAIL(buffer_size > 4, error_msg, return);
236 size_t file_buf_size = 3 * (1 + buffer_size);
237 file_buf = (char *)calloc(1, file_buf_size);
238 ENSURE_OR_FAIL(file_buf != nullptr, error_msg, return);
239
240 std::copy(buf.begin(), buf.end(), file_buf);
241 file_buf[buffer_size] = 0;
242 // This is for fixing degenerate utf8
243 char *arena = &file_buf[buffer_size + 1];
244 char *arena_end = file_buf + file_buf_size - 1;
245 *arena_end = 0;
246
247 /*
248 * Some non-encrypted, but zip-encoded files are popping up now and then.
249 *
250 * Thanks to piernov for noticing the starting byte sequence
251 *
252 * Attempt to decode using the decode() call and subsequently
253 * split the file to get the content. If that fails, then try again
254 * without decoding.
255 */
256
257 uint8_t s1 = file_buf[4];
258 uint8_t s2 = file_buf[5];
259 if (!((s1 == 0x78) && ((s2 == 0x9C) || (s2 == 0xDA)))) {
260
261 /*
262 * Doesn't have the zlib signature, so decode it first.
263 *
264 * 1 in ~2^16 chance of a false hit.
265 */
266 FZFile::decode(file_buf, buffer_size); // RC6 decryption
267 // fprintf(stderr,"FZFile:Decoded\n");
268 }
269
270 size_t content_size = 0;
271 size_t descr_size = 0;
272 char *descr;
273 char *content = FZFile::split(file_buf, buffer_size, content_size, descr, descr_size); // then split it
274
275 /*

Callers 1

LoadFileMethod · 0.80

Calls 2

stringfileFunction · 0.85
split_stringFunction · 0.85

Tested by

no test coverage detected