diff 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
line wrap: on
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/win32/7zip/7z/CPP/7zip/Archive/Lzma/LzmaIn.cpp	Sat Mar 03 10:31:27 2012 -0600
     1.3 @@ -0,0 +1,56 @@
     1.4 +// Archive/LzmaIn.cpp
     1.5 +
     1.6 +#include "StdAfx.h"
     1.7 +
     1.8 +#include "LzmaIn.h"
     1.9 +
    1.10 +#include "../../Common/StreamUtils.h"
    1.11 +
    1.12 +namespace NArchive {
    1.13 +namespace NLzma {
    1.14 + 
    1.15 +static bool CheckDictSize(const Byte *p)
    1.16 +{
    1.17 +  UInt32 dicSize = GetUi32(p);
    1.18 +  int i;
    1.19 +  for (i = 1; i <= 30; i++)
    1.20 +    if (dicSize == ((UInt32)2 << i) || dicSize == ((UInt32)3 << i))
    1.21 +      return true;
    1.22 +  return false;
    1.23 +}
    1.24 +
    1.25 +HRESULT ReadStreamHeader(ISequentialInStream *inStream, CHeader &block)
    1.26 +{
    1.27 +  Byte sig[5 + 9];
    1.28 +  RINOK(ReadStream_FALSE(inStream, sig, 5 + 8));
    1.29 +
    1.30 +  const Byte kMaxProp0Val = 5 * 5 * 9 - 1;
    1.31 +  if (sig[0] > kMaxProp0Val)
    1.32 +    return S_FALSE;
    1.33 +
    1.34 +  for (int i = 0; i < 5; i++)
    1.35 +    block.LzmaProps[i] = sig[i];
    1.36 +  
    1.37 +  block.IsThereFilter = false;
    1.38 +  block.FilterMethod = 0;
    1.39 +
    1.40 +  if (!CheckDictSize(sig + 1))
    1.41 +  {
    1.42 +    if (sig[0] > 1 || sig[1] > kMaxProp0Val)
    1.43 +      return S_FALSE;
    1.44 +    block.IsThereFilter = true;
    1.45 +    block.FilterMethod = sig[0];
    1.46 +    for (int i = 0; i < 5; i++)
    1.47 +      block.LzmaProps[i] = sig[i + 1];
    1.48 +    if (!CheckDictSize(block.LzmaProps + 1))
    1.49 +      return S_FALSE;
    1.50 +    RINOK(ReadStream_FALSE(inStream, sig + 5 + 8, 1));
    1.51 +  }
    1.52 +  UInt32 unpOffset = 5 + (block.IsThereFilter ? 1 : 0);
    1.53 +  block.UnpackSize = GetUi64(sig + unpOffset);
    1.54 +  if (block.HasUnpackSize() && block.UnpackSize >= ((UInt64)1 << 56))
    1.55 +    return S_FALSE;
    1.56 +  return S_OK;
    1.57 +}
    1.58 +
    1.59 +}}