From 02d6107c97b48888362e7c6a70dcac323c89d741 Mon Sep 17 00:00:00 2001 From: Tomas Bzatek Date: Sun, 17 Dec 2023 21:23:58 +0100 Subject: ZipArchive: Update to the 4.6.9 release --- zip/ZipArchive/ZipExtraData.cpp | 40 ++++++++++++++++++++++++++++------------ 1 file changed, 28 insertions(+), 12 deletions(-) (limited to 'zip/ZipArchive/ZipExtraData.cpp') diff --git a/zip/ZipArchive/ZipExtraData.cpp b/zip/ZipArchive/ZipExtraData.cpp index 8712234..f6e5a4f 100644 --- a/zip/ZipArchive/ZipExtraData.cpp +++ b/zip/ZipArchive/ZipExtraData.cpp @@ -1,6 +1,6 @@ //////////////////////////////////////////////////////////////////////////////// -// This source file is part of the ZipArchive library source distribution and -// is Copyrighted 2000 - 2007 by Artpol Software - Tadeusz Dracz +// This source file is part of the ZipArchive Library Open Source distribution +// and is Copyrighted 2000 - 2022 by Artpol Software - Tadeusz Dracz // // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License @@ -9,7 +9,7 @@ // // For the licensing details refer to the License.txt file. // -// Web Site: http://www.artpol-software.com +// Web Site: https://www.artpol-software.com //////////////////////////////////////////////////////////////////////////////// #include "stdafx.h" @@ -22,14 +22,25 @@ using namespace ZipArchiveLib; bool CZipExtraData::Read(char* buffer, WORD uSize) { if (uSize < 4) - return false; - WORD size; - CBytesWriter::ReadBytes(m_uHeaderID, buffer); - CBytesWriter::ReadBytes(size, buffer + 2); - if (uSize - 4 < size) return false; - m_data.Allocate(size); - memcpy(m_data, buffer + 4, size); + CBytesWriter::ReadBytes(m_uHeaderID, buffer); + m_bHasSize = CZipExtraField::HasSize(m_uHeaderID); + WORD size; + if (m_bHasSize) + { + CBytesWriter::ReadBytes(size, buffer + 2); + if (size > (WORD)(uSize - 4)) + return false; + m_data.Allocate(size); + memcpy(m_data, buffer + 4, size); + } + else + { + // The size is not always relevant (in extra headers not conforming to the standard) + size = (WORD)(uSize - 2); + m_data.Allocate(size); + memcpy(m_data, buffer + 2, size); + } return true; } @@ -37,7 +48,12 @@ WORD CZipExtraData::Write(char* buffer)const { CBytesWriter::WriteBytes(buffer, m_uHeaderID); WORD size = (WORD)m_data.GetSize(); - CBytesWriter::WriteBytes(buffer + 2, size); - memcpy(buffer + 4, m_data, size); + buffer += 2; + if (m_bHasSize) + { + CBytesWriter::WriteBytes(buffer, size); + buffer += 2; + } + memcpy(buffer, m_data, size); return (WORD)(size + 4); } -- cgit v1.2.3