Mercurial > vba-linux
comparison src/win32/7zip/7z/CPP/7zip/Archive/Lzma/LzmaIn.cpp @ 1:f9f4f1b99eed
importing src directory
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Sat, 03 Mar 2012 10:31:27 -0600 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
0:8ced16adf2e1 | 1:f9f4f1b99eed |
---|---|
1 // Archive/LzmaIn.cpp | |
2 | |
3 #include "StdAfx.h" | |
4 | |
5 #include "LzmaIn.h" | |
6 | |
7 #include "../../Common/StreamUtils.h" | |
8 | |
9 namespace NArchive { | |
10 namespace NLzma { | |
11 | |
12 static bool CheckDictSize(const Byte *p) | |
13 { | |
14 UInt32 dicSize = GetUi32(p); | |
15 int i; | |
16 for (i = 1; i <= 30; i++) | |
17 if (dicSize == ((UInt32)2 << i) || dicSize == ((UInt32)3 << i)) | |
18 return true; | |
19 return false; | |
20 } | |
21 | |
22 HRESULT ReadStreamHeader(ISequentialInStream *inStream, CHeader &block) | |
23 { | |
24 Byte sig[5 + 9]; | |
25 RINOK(ReadStream_FALSE(inStream, sig, 5 + 8)); | |
26 | |
27 const Byte kMaxProp0Val = 5 * 5 * 9 - 1; | |
28 if (sig[0] > kMaxProp0Val) | |
29 return S_FALSE; | |
30 | |
31 for (int i = 0; i < 5; i++) | |
32 block.LzmaProps[i] = sig[i]; | |
33 | |
34 block.IsThereFilter = false; | |
35 block.FilterMethod = 0; | |
36 | |
37 if (!CheckDictSize(sig + 1)) | |
38 { | |
39 if (sig[0] > 1 || sig[1] > kMaxProp0Val) | |
40 return S_FALSE; | |
41 block.IsThereFilter = true; | |
42 block.FilterMethod = sig[0]; | |
43 for (int i = 0; i < 5; i++) | |
44 block.LzmaProps[i] = sig[i + 1]; | |
45 if (!CheckDictSize(block.LzmaProps + 1)) | |
46 return S_FALSE; | |
47 RINOK(ReadStream_FALSE(inStream, sig + 5 + 8, 1)); | |
48 } | |
49 UInt32 unpOffset = 5 + (block.IsThereFilter ? 1 : 0); | |
50 block.UnpackSize = GetUi64(sig + unpOffset); | |
51 if (block.HasUnpackSize() && block.UnpackSize >= ((UInt64)1 << 56)) | |
52 return S_FALSE; | |
53 return S_OK; | |
54 } | |
55 | |
56 }} |