other-licenses/7zstub/src/7zip/Common/StreamUtils.cpp

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rw-r--r--

Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

     1 // StreamUtils.cpp
     3 #include "StdAfx.h"
     5 #include "../../Common/MyCom.h"
     6 #include "StreamUtils.h"
     8 HRESULT ReadStream(ISequentialInStream *stream, void *data, UInt32 size, UInt32 *processedSize)
     9 {
    10   if (processedSize != 0)
    11     *processedSize = 0;
    12   while(size != 0)
    13   {
    14     UInt32 processedSizeLoc; 
    15     HRESULT res = stream->Read(data, size, &processedSizeLoc);
    16     if (processedSize != 0)
    17       *processedSize += processedSizeLoc;
    18     data = (Byte *)((Byte *)data + processedSizeLoc);
    19     size -= processedSizeLoc;
    20     RINOK(res);
    21     if (processedSizeLoc == 0)
    22       return S_OK;
    23   }
    24   return S_OK;
    25 }
    27 HRESULT WriteStream(ISequentialOutStream *stream, const void *data, UInt32 size, UInt32 *processedSize)
    28 {
    29   if (processedSize != 0)
    30     *processedSize = 0;
    31   while(size != 0)
    32   {
    33     UInt32 processedSizeLoc; 
    34     HRESULT res = stream->Write(data, size, &processedSizeLoc);
    35     if (processedSize != 0)
    36       *processedSize += processedSizeLoc;
    37     data = (const void *)((const Byte *)data + processedSizeLoc);
    38     size -= processedSizeLoc;
    39     RINOK(res);
    40     if (processedSizeLoc == 0)
    41       break;
    42   }
    43   return S_OK;
    44 }

mercurial