diff options
Diffstat (limited to '7zip/Archive/cpio/CpioIn.cpp')
-rwxr-xr-x | 7zip/Archive/cpio/CpioIn.cpp | 47 |
1 files changed, 28 insertions, 19 deletions
diff --git a/7zip/Archive/cpio/CpioIn.cpp b/7zip/Archive/cpio/CpioIn.cpp index ce2ab023..32b9f77d 100755 --- a/7zip/Archive/cpio/CpioIn.cpp +++ b/7zip/Archive/cpio/CpioIn.cpp @@ -4,8 +4,11 @@ #include "CpioIn.h" +#include "Common/StringToInt.h" #include "Windows/Defs.h" +#include "../../Common/StreamUtils.h" + #include "CpioHeader.h" namespace NArchive { @@ -13,7 +16,7 @@ namespace NCpio { HRESULT CInArchive::ReadBytes(void *data, UInt32 size, UInt32 &processedSize) { - RINOK(m_Stream->Read(data, size, &processedSize)); + RINOK(ReadStream(m_Stream, data, size, &processedSize)); m_Position += processedSize; return S_OK; } @@ -75,24 +78,37 @@ bool CInArchive::ReadNumber(UInt32 &resultValue) return true; } +static bool OctalToNumber(const char *s, UInt64 &res) +{ + const char *end; + res = ConvertOctStringToUInt64(s, &end); + return (*end == ' ' || *end == 0); +} + +static bool OctalToNumber32(const char *s, UInt32 &res) +{ + UInt64 res64; + if (!OctalToNumber(s, res64)) + return false; + res = (UInt32)res64; + return (res64 <= 0xFFFFFFFF); +} + bool CInArchive::ReadOctNumber(int size, UInt32 &resultValue) { - char s[32]; + char sz[32 + 4]; int i; for (i = 0; i < size && i < 32; i++) - s[i] = char(ReadByte()); - s[i] = 0; - char *endPtr; - resultValue = strtoul(s, &endPtr, 8); - return true; + sz[i] = (char)ReadByte(); + sz[i] = 0; + return OctalToNumber32(sz, resultValue); } -#define GetFromHex(y) { if (!ReadNumber(y)) return E_FAIL; } -#define GetFromOct6(y) { if (!ReadOctNumber(6, y)) return E_FAIL; } -#define GetFromOct11(y) { if (!ReadOctNumber(11, y)) return E_FAIL; } +#define GetFromHex(y) { if (!ReadNumber(y)) return S_FALSE; } +#define GetFromOct6(y) { if (!ReadOctNumber(6, y)) return S_FALSE; } +#define GetFromOct11(y) { if (!ReadOctNumber(11, y)) return S_FALSE; } -static unsigned short ConvertValue( - unsigned short value, bool convert) +static unsigned short ConvertValue(unsigned short value, bool convert) { if (!convert) return value; @@ -109,13 +125,6 @@ static UInt32 GetAlignedSize(UInt32 size, UInt32 align) HRESULT CInArchive::GetNextItem(bool &filled, CItemEx &item) { - /* - union - { - NFileHeader::CRecord record; - NFileHeader::CRecord2 record2; - }; - */ filled = false; UInt32 processedSize; |