summaryrefslogtreecommitdiff
path: root/zip/ZipArchive/ZipExtraData.cpp
diff options
context:
space:
mode:
authorTomas Bzatek <tbzatek@redhat.com>2023-12-17 21:23:58 +0100
committerTomas Bzatek <tbzatek@redhat.com>2023-12-17 21:23:58 +0100
commit02d6107c97b48888362e7c6a70dcac323c89d741 (patch)
tree5069a77adaf73f7249ac79b6c49a47168a647ef8 /zip/ZipArchive/ZipExtraData.cpp
parent4e17c2527b106f1b493a3ac77c89858d14f834e2 (diff)
downloadtuxcmd-modules-02d6107c97b48888362e7c6a70dcac323c89d741.tar.xz
ZipArchive: Update to the 4.6.9 release
Diffstat (limited to 'zip/ZipArchive/ZipExtraData.cpp')
-rw-r--r--zip/ZipArchive/ZipExtraData.cpp40
1 files changed, 28 insertions, 12 deletions
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);
}