295 {
296
297
298 const size_t headerSize = signatureSize + signaturePadding + 2 * bytesInIndex;
299
300
301 std::vector<sk_sp<SkData>>
parts;
302
303
304 size_t partsTotalSize = 0;
305
306
307 uint32_t foundPartCount = 0;
308
309
310 uint32_t expectedPartCount = 0;
311
312
313 for (
const auto&
marker : markerList) {
314
316 continue;
317 }
318
319
320 const size_t dataLength =
marker.fData->size();
321 if (dataLength <= headerSize) {
322 continue;
323 }
324
325
326
328 uint32_t partIndex = 0;
329 uint32_t partCount = 0;
330 if (bytesInIndex == 0) {
331 partIndex = 1;
332 partCount = 1;
333 } else {
334 for (
size_t i = 0;
i < bytesInIndex; ++
i) {
335 const size_t offset = signatureSize + signaturePadding;
337 partCount = (partCount << 8) +
data[
offset + bytesInIndex +
i];
338 }
339 }
340
341
342 if (!partCount) {
344 return nullptr;
345 }
346
347
348 if (partIndex <= 0 || partIndex > partCount) {
349 SkCodecPrintf(
"Invalid marker index %u for count %u\n", partIndex, partCount);
350 return nullptr;
351 }
352
353
354 if (expectedPartCount == 0) {
355 expectedPartCount = partCount;
356 parts.resize(expectedPartCount);
357 }
358
359
360 if (partCount != expectedPartCount) {
361 SkCodecPrintf(
"Conflicting marker counts %u vs %u\n", partCount, expectedPartCount);
362 return nullptr;
363 }
364
365
367
368
369 if (
parts[partIndex - 1]) {
370 SkCodecPrintf(
"Duplicate parts for index %u of %u\n", partIndex, expectedPartCount);
371 return nullptr;
372 }
373
374
375 partsTotalSize += partData->size();
376 parts[partIndex - 1] = std::move(partData);
377 foundPartCount += 1;
378
379
380 if (foundPartCount == expectedPartCount) {
381 break;
382 }
383 }
384
385
386 if (expectedPartCount == 0) {
387 return nullptr;
388 }
389
390
391 if (foundPartCount != expectedPartCount) {
392 SkCodecPrintf(
"Incomplete set of markers (expected %u got %u)\n",
393 expectedPartCount,
394 foundPartCount);
395 return nullptr;
396 }
397
398
399 if (!alwaysCopyData && expectedPartCount == 1) {
400 return std::move(
parts[0]);
401 }
402
403
405 void* copyDest =
result->writable_data();
406 for (
const auto& part :
parts) {
407 memcpy(copyDest, part->data(), part->size());
408 copyDest = SkTAddOffset<void>(copyDest, part->size());
409 }
411}
#define SkCodecPrintf(...)
static sk_sp< SkData > MakeWithoutCopy(const void *data, size_t length)
static sk_sp< SkData > MakeUninitialized(size_t length)
std::shared_ptr< const fml::Mapping > data