X-Git-Url: https://git.carlh.net/gitweb/?a=blobdiff_plain;f=src%2FJP2K_Codestream_Parser.cpp;h=f4596a87e5ceb889faa2ebf6746aca5390ee448d;hb=57ddb7894042229bbc5f14e9257068afcc6f8725;hp=216827b2bdf3e265f126d54cbbf2bc9b3d5ada10;hpb=8095eaa320551b6795d0368c0ad0c227a3167caa;p=asdcplib.git diff --git a/src/JP2K_Codestream_Parser.cpp b/src/JP2K_Codestream_Parser.cpp index 216827b..f4596a8 100755 --- a/src/JP2K_Codestream_Parser.cpp +++ b/src/JP2K_Codestream_Parser.cpp @@ -1,5 +1,5 @@ /* -Copyright (c) 2004, John Hurst +Copyright (c) 2004-2006, John Hurst All rights reserved. Redistribution and use in source and binary forms, with or without @@ -29,10 +29,12 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. \brief AS-DCP library, JPEG 2000 codestream essence reader implementation */ +#include #include -#include #include #include +#include +using Kumu::DefaultLogSink; //------------------------------------------------------------------------------------------ @@ -42,7 +44,7 @@ class ASDCP::JP2K::CodestreamParser::h__CodestreamParser public: PictureDescriptor m_PDesc; - FileReader m_File; + Kumu::FileReader m_File; h__CodestreamParser() { @@ -61,11 +63,11 @@ public: if ( ASDCP_SUCCESS(result) ) { - fsize_t file_size = m_File.Size(); + Kumu::fsize_t file_size = m_File.Size(); if ( FB.Capacity() < file_size ) { - DefaultLogSink().Error("FrameBuf.Capacity: %lu frame length: %lu\n", FB.Capacity(), (ui32_t)file_size); + DefaultLogSink().Error("FrameBuf.Capacity: %u frame length: %u\n", FB.Capacity(), (ui32_t)file_size); return RESULT_SMALLBUF; } } @@ -88,10 +90,12 @@ public: while ( p < end_p && ASDCP_SUCCESS(result) ) { result = GetNextMarker(&p, NextMarker); -#if 0 - fprintf(stderr, "%s Length: %lu\n", - GetMarkerString(NextMarker.m_Type), NextMarker.m_DataSize); -#endif + + if ( ASDCP_FAILURE(result) ) + { + result = RESULT_RAW_ESS; + break; + } switch ( NextMarker.m_Type ) { @@ -119,7 +123,7 @@ public: if ( m_PDesc.Csize != 3 ) { - DefaultLogSink().Error("Unexpected number of components: %lu\n", m_PDesc.Csize); + DefaultLogSink().Error("Unexpected number of components: %u\n", m_PDesc.Csize); return RESULT_RAW_FORMAT; } @@ -129,25 +133,34 @@ public: break; case MRK_COD: - if ( NextMarker.m_DataSize > DefaultCodingDataLength ) + memset(&m_PDesc.CodingStyleDefault, 0, sizeof(CodingStyleDefault_t)); + + if ( NextMarker.m_DataSize > sizeof(CodingStyleDefault_t) ) { - DefaultLogSink().Error("Unexpectedly large CodingStyle data: %lu\n", NextMarker.m_DataSize); + DefaultLogSink().Error("Unexpectedly large CodingStyle data: %u\n", NextMarker.m_DataSize); return RESULT_RAW_FORMAT; } - m_PDesc.CodingStyleLength = NextMarker.m_DataSize; - memcpy(m_PDesc.CodingStyle, NextMarker.m_Data, m_PDesc.CodingStyleLength); + memcpy(&m_PDesc.CodingStyleDefault, NextMarker.m_Data, NextMarker.m_DataSize); break; case MRK_QCD: - if ( NextMarker.m_DataSize > DefaultCodingDataLength ) + memset(&m_PDesc.QuantizationDefault, 0, sizeof(QuantizationDefault_t)); + + if ( NextMarker.m_DataSize < 16 ) + { + DefaultLogSink().Error("No quantization signaled\n"); + return RESULT_RAW_FORMAT; + } + + if ( NextMarker.m_DataSize > MaxDefaults ) { - DefaultLogSink().Error("Unexpectedly large QuantDefault data: %lu\n", NextMarker.m_DataSize); + DefaultLogSink().Error("Quantization Default length exceeds maximum %d\n", NextMarker.m_DataSize); return RESULT_RAW_FORMAT; } - m_PDesc.QuantDefaultLength = NextMarker.m_DataSize; - memcpy(m_PDesc.QuantDefault, NextMarker.m_Data, m_PDesc.QuantDefaultLength); + memcpy(&m_PDesc.QuantizationDefault, NextMarker.m_Data, NextMarker.m_DataSize); + m_PDesc.QuantizationDefault.SPqcdLength = NextMarker.m_DataSize - 1; break; } }