diff options
| author | jhurst <jhurst@cinecert.com> | 2021-11-10 12:52:24 -0800 |
|---|---|---|
| committer | jhurst <jhurst@cinecert.com> | 2021-11-10 12:52:24 -0800 |
| commit | de79726588c46d1c0756808075e8d96b5628e2c5 (patch) | |
| tree | 549ed0a4a79fc8443c911dee452626ca89ce8b2c /src/KLV.cpp | |
| parent | feba38c3802863fe783a750e0f866af9ad834f7f (diff) | |
Modified the KLV parser to return RESULT_ALLOC instead of RESULT_FAIL when an attempt is made to read a packet that is larger than the internal limit. The file handle is Seek()ed to the first byte following the huge packet, allowing the caller to get over it and continue parsing MXF.
Diffstat (limited to 'src/KLV.cpp')
| -rwxr-xr-x | src/KLV.cpp | 26 |
1 files changed, 18 insertions, 8 deletions
diff --git a/src/KLV.cpp b/src/KLV.cpp index 681a834..c29eb8c 100755 --- a/src/KLV.cpp +++ b/src/KLV.cpp @@ -1,5 +1,5 @@ /* -Copyright (c) 2005-2009, John Hurst +Copyright (c) 2005-2021, John Hurst All rights reserved. Redistribution and use in source and binary forms, with or without @@ -167,14 +167,13 @@ ASDCP::KLVPacket::Dump(FILE* stream, const Dictionary& Dict, bool show_value) if ( m_KeyStart != 0 ) { - assert(m_ValueStart); UL TmpUL(m_KeyStart); fprintf(stream, "%s", TmpUL.EncodeString(buf, 64)); const MDDEntry* Entry = Dict.FindULAnyVersion(m_KeyStart); fprintf(stream, " len: %7llu (%s)\n", m_ValueLength, (Entry ? Entry->name : "Unknown")); - if ( show_value && m_ValueLength < 1000 ) + if ( m_ValueStart && show_value && m_ValueLength < 1000 ) Kumu::hexdump(m_ValueStart, Kumu::xmin(m_ValueLength, (ui64_t)128), stream); } else if ( m_UL.HasValue() ) @@ -234,16 +233,27 @@ ASDCP::KLVFilePacket::InitFromFile(const Kumu::IFileReader& Reader) return RESULT_FAIL; } + ui32_t ber_len = Kumu::BER_length(tmp_data + SMPTE_UL_LENGTH); + m_KLLength = SMPTE_UL_LENGTH + ber_len; + if ( tmp_size > MAX_KLV_PACKET_LENGTH ) { - Kumu::ui64Printer tmp_size_str(tmp_size); - DefaultLogSink().Error("Packet length %s exceeds internal limit\n", tmp_size_str.c_str()); - return RESULT_FAIL; + result = Reader.Seek(tmp_size - (tmp_read_size - SMPTE_UL_LENGTH - ber_len), Kumu::SP_POS); + + if ( ASDCP_SUCCESS(result) ) + { + memcpy(m_Buffer.Data(), tmp_data, SMPTE_UL_LENGTH); + m_KeyStart = m_Buffer.Data(); + + Kumu::ui64Printer tmp_size_str(tmp_size); + DefaultLogSink().Error("Packet length %s exceeds internal limit.\n", tmp_size_str.c_str()); + result = RESULT_ALLOC; + } + + return result; } ui32_t remainder = 0; - ui32_t ber_len = Kumu::BER_length(tmp_data + SMPTE_UL_LENGTH); - m_KLLength = SMPTE_UL_LENGTH + ber_len; assert(tmp_size <= 0xFFFFFFFFL); m_ValueLength = (ui32_t) tmp_size; ui32_t packet_length = m_ValueLength + m_KLLength; |
