diff options
| author | jhurst <jhurst@cinecert.com> | 2010-06-09 21:27:32 +0000 |
|---|---|---|
| committer | jhurst <> | 2010-06-09 21:27:32 +0000 |
| commit | a3900f7b93b5f405a3c6a414aafb7099f2a5c6da (patch) | |
| tree | 6f22cfeacd69ccd45b7dd044968a0f6f6d5fc8cb /src/h__Reader.cpp | |
| parent | fab4dcb49724dc9cdade3857a3f438c22c1df0f9 (diff) | |
buggy less
Diffstat (limited to 'src/h__Reader.cpp')
| -rwxr-xr-x | src/h__Reader.cpp | 51 |
1 files changed, 43 insertions, 8 deletions
diff --git a/src/h__Reader.cpp b/src/h__Reader.cpp index a463ae1..b0f8870 100755 --- a/src/h__Reader.cpp +++ b/src/h__Reader.cpp @@ -1,5 +1,5 @@ /* -Copyright (c) 2004-2009, John Hurst +Copyright (c) 2004-2010, John Hurst All rights reserved. Redistribution and use in source and binary forms, with or without @@ -159,16 +159,51 @@ ASDCP::KLReader::ReadKLFromFile(Kumu::FileReader& Reader) ui32_t header_length = SMPTE_UL_LENGTH + MXF_BER_LENGTH; Result_t result = Reader.Read(m_KeyBuf, header_length, &read_count); - if ( ASDCP_SUCCESS(result) ) + if ( ASDCP_FAILURE(result) ) + return result; + + if ( read_count != header_length ) + return RESULT_READFAIL; + + const byte_t* ber_start = m_KeyBuf + SMPTE_UL_LENGTH; + + if ( ( *ber_start & 0x80 ) == 0 ) { - if ( read_count != header_length ) - result = RESULT_READFAIL; - - else - result = InitFromBuffer(m_KeyBuf, header_length); + DefaultLogSink().Error("BER encoding error.\n"); + return RESULT_FORMAT; } - return result; + ui8_t ber_size = ( *ber_start & 0x0f ) + 1; + + if ( ber_size > 9 ) + { + DefaultLogSink().Error("BER size encoding error.\n"); + return RESULT_FORMAT; + } + + if ( ber_size < MXF_BER_LENGTH ) + { + DefaultLogSink().Error("BER size %d shorter than AS-DCP minimum %d.\n", + ber_size, MXF_BER_LENGTH); + return RESULT_FORMAT; + } + + if ( ber_size > MXF_BER_LENGTH ) + { + ui32_t diff = ber_size - MXF_BER_LENGTH; + assert((SMPTE_UL_LENGTH + MXF_BER_LENGTH + diff) <= (SMPTE_UL_LENGTH * 2)); + result = Reader.Read(m_KeyBuf + SMPTE_UL_LENGTH + MXF_BER_LENGTH, diff, &read_count); + + if ( ASDCP_FAILURE(result) ) + return result; + + if ( read_count != diff ) + return RESULT_READFAIL; + + header_length += diff; + } + + return InitFromBuffer(m_KeyBuf, header_length); } // standard method of reading a plaintext or encrypted frame |
