diff options
author | 2016-04-09 21:45:54 +1000 | |
---|---|---|
committer | 2016-04-09 21:52:08 +1000 | |
commit | e925c494fe30adafb615c075f5eb692dd2b2effa (patch) | |
tree | eed0b7ccadb049ed2dc8a72282c0235c4e94b6ae /src | |
parent | b13e02f9751424dfc9ce6070676e2e318087a991 (diff) |
Update LZMA SDK to 15.14
Diffstat (limited to 'src')
-rw-r--r-- | src/lib/util/chdcodec.cpp | 29 | ||||
-rw-r--r-- | src/lib/util/un7z.cpp | 15 |
2 files changed, 29 insertions, 15 deletions
diff --git a/src/lib/util/chdcodec.cpp b/src/lib/util/chdcodec.cpp index be1d2022cd7..ba1840489d6 100644 --- a/src/lib/util/chdcodec.cpp +++ b/src/lib/util/chdcodec.cpp @@ -1128,20 +1128,35 @@ chd_lzma_decompressor::chd_lzma_decompressor(chd_file &chd, UINT32 hunkbytes, bo // construct the decoder LzmaDec_Construct(&m_decoder); + // FIXME: this code is written in a way that makes it impossible to safely upgrade the LZMA SDK + // This code assumes that the current version of the encoder imposes the same requirements on the + // decoder as the encoder used to produce the file. This is not necessarily true. The format + // needs to be changed so the encoder properties are written to the file. + // configure the properties like the compressor did CLzmaEncProps encoder_props; chd_lzma_compressor::configure_properties(encoder_props, hunkbytes); // convert to decoder properties - CLzmaProps decoder_props; - decoder_props.lc = encoder_props.lc; - decoder_props.lp = encoder_props.lp; - decoder_props.pb = encoder_props.pb; - decoder_props.dicSize = encoder_props.dictSize; + CLzmaEncHandle enc = LzmaEnc_Create(&m_allocator); + if (!enc) + throw CHDERR_DECOMPRESSION_ERROR; + if (LzmaEnc_SetProps(enc, &encoder_props) != SZ_OK) + { + LzmaEnc_Destroy(enc, &m_allocator, &m_allocator); + throw CHDERR_DECOMPRESSION_ERROR; + } + Byte decoder_props[LZMA_PROPS_SIZE]; + SizeT props_size = sizeof(decoder_props); + if (LzmaEnc_WriteProperties(enc, decoder_props, &props_size) != SZ_OK) + { + LzmaEnc_Destroy(enc, &m_allocator, &m_allocator); + throw CHDERR_DECOMPRESSION_ERROR; + } + LzmaEnc_Destroy(enc, &m_allocator, &m_allocator); // do memory allocations - SRes res = LzmaDec_Allocate_MAME(&m_decoder, &decoder_props, &m_allocator); - if (res != SZ_OK) + if (LzmaDec_Allocate(&m_decoder, decoder_props, LZMA_PROPS_SIZE, &m_allocator) != SZ_OK) throw CHDERR_DECOMPRESSION_ERROR; } diff --git a/src/lib/util/un7z.cpp b/src/lib/util/un7z.cpp index 5822479c4f0..a2fbf380d35 100644 --- a/src/lib/util/un7z.cpp +++ b/src/lib/util/un7z.cpp @@ -404,25 +404,24 @@ int m7z_file_impl::search( bool matchname, bool partialpath) { - for ( ; i < m_db.db.NumFiles; i++) + for ( ; i < m_db.NumFiles; i++) { - const CSzFileItem &f(m_db.db.Files[i]); - make_utf8_name(i); - const std::uint64_t size(f.Size); - const std::uint32_t crc(f.Crc); - const bool crcmatch(crc == search_crc); + bool const is_dir(SzArEx_IsDir(&m_db, i)); + const std::uint64_t size(SzArEx_GetFileSize(&m_db, i)); + const std::uint32_t crc(m_db.CRCs.Vals[i]); + const bool crcmatch(SzBitArray_Check(m_db.CRCs.Defs, i) && (crc == search_crc)); auto const partialoffset(m_utf8_buf.size() - 1 - search_filename.length()); bool const partialpossible((m_utf8_buf.size() > (search_filename.length() + 1)) && (m_utf8_buf[partialoffset - 1] == '/')); const bool namematch( !core_stricmp(search_filename.c_str(), &m_utf8_buf[0]) || (partialpath && partialpossible && !core_stricmp(search_filename.c_str(), &m_utf8_buf[partialoffset]))); - const bool found = ((!matchcrc && !matchname) || !f.IsDir) && (!matchcrc || crcmatch) && (!matchname || namematch); + const bool found = ((!matchcrc && !matchname) || !is_dir) && (!matchcrc || crcmatch) && (!matchname || namematch); if (found) { m_curr_file_idx = i; - m_curr_is_dir = bool(f.IsDir); + m_curr_is_dir = is_dir; m_curr_name = &m_utf8_buf[0]; m_curr_length = size; m_curr_crc = crc; |