| 1 | /* |
| 2 | * Copyright (C) 2017 Apple Inc. All rights reserved. |
| 3 | * Copyright (C) 2018 Metrological Group B.V. |
| 4 | * Copyright (C) 2018 Igalia S.L |
| 5 | * |
| 6 | * Redistribution and use in source and binary forms, with or without |
| 7 | * modification, are permitted provided that the following conditions |
| 8 | * are met: |
| 9 | * 1. Redistributions of source code must retain the above copyright |
| 10 | * notice, this list of conditions and the following disclaimer. |
| 11 | * 2. Redistributions in binary form must reproduce the above copyright |
| 12 | * notice, this list of conditions and the following disclaimer in the |
| 13 | * documentation and/or other materials provided with the distribution. |
| 14 | * |
| 15 | * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' |
| 16 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, |
| 17 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 18 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS |
| 19 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 20 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 21 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 22 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 23 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 24 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
| 25 | * THE POSSIBILITY OF SUCH DAMAGE. |
| 26 | */ |
| 27 | |
| 28 | #include "config.h" |
| 29 | #include "ISOProtectionSystemSpecificHeaderBox.h" |
| 30 | |
| 31 | #include <JavaScriptCore/DataView.h> |
| 32 | |
| 33 | using JSC::DataView; |
| 34 | |
| 35 | namespace WebCore { |
| 36 | |
| 37 | bool ISOProtectionSystemSpecificHeaderBox::(DataView& view, unsigned& offset) |
| 38 | { |
| 39 | if (!ISOFullBox::parse(view, offset)) |
| 40 | return false; |
| 41 | |
| 42 | // ISO/IEC 23001-7-2016 Section 8.1.1 |
| 43 | auto buffer = view.possiblySharedBuffer(); |
| 44 | if (!buffer) |
| 45 | return false; |
| 46 | auto systemID = buffer->slice(offset, offset + 16); |
| 47 | offset += 16; |
| 48 | |
| 49 | m_systemID.resize(16); |
| 50 | memcpy(m_systemID.data(), systemID->data(), 16); |
| 51 | |
| 52 | if (m_version) { |
| 53 | uint32_t keyIDCount = 0; |
| 54 | if (!checkedRead<uint32_t>(keyIDCount, view, offset, BigEndian)) |
| 55 | return false; |
| 56 | if (buffer->byteLength() - offset < keyIDCount * 16) |
| 57 | return false; |
| 58 | m_keyIDs.resize(keyIDCount); |
| 59 | for (unsigned keyID = 0; keyID < keyIDCount; keyID++) { |
| 60 | auto& currentKeyID = m_keyIDs[keyID]; |
| 61 | currentKeyID.resize(16); |
| 62 | auto parsedKeyID = buffer->slice(offset, offset + 16); |
| 63 | offset += 16; |
| 64 | memcpy(currentKeyID.data(), parsedKeyID->data(), 16); |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | uint32_t dataSize = 0; |
| 69 | if (!checkedRead<uint32_t>(dataSize, view, offset, BigEndian)) |
| 70 | return false; |
| 71 | if (buffer->byteLength() - offset < dataSize) |
| 72 | return false; |
| 73 | auto parsedData = buffer->slice(offset, offset + dataSize); |
| 74 | offset += dataSize; |
| 75 | |
| 76 | m_data.resize(dataSize); |
| 77 | memcpy(m_data.data(), parsedData->data(), dataSize); |
| 78 | |
| 79 | return true; |
| 80 | } |
| 81 | |
| 82 | } |
| 83 | |