deps/unrar/qopen.cpp
// Fill RawRead object from buffer.
Fill RawRead object from buffer.
Fill RawRead object from buffer .
bool QuickOpen::ReadRaw(RawRead &Raw)
{
  if (MaxBufSize-ReadBufPos<0x100) 
  {
    size_t DataLeft=ReadBufSize-ReadBufPos;
    memcpy(Buf,Buf+ReadBufPos,DataLeft);
    ReadBufPos=0;
    ReadBufSize=DataLeft;
    ReadBuffer();
  }
  const size_t FirstReadSize=7;
  if (ReadBufPos+FirstReadSize>ReadBufSize)
    return false;
  Raw.Read(Buf+ReadBufPos,FirstReadSize);
  ReadBufPos+=FirstReadSize;
  uint SavedCRC=Raw.Get4();
  uint SizeBytes=Raw.GetVSize(4);
  uint64 BlockSize=Raw.GetV();
  int SizeToRead=int(BlockSize);
  SizeToRead-=FirstReadSize-SizeBytes-4; 
  if (SizeToRead<0 || SizeBytes==0 || BlockSize==0)
  {
    Loaded=false; 
    return false;
  }
  while (SizeToRead>0)
  {
    size_t DataLeft=ReadBufSize-ReadBufPos;
    size_t CurSizeToRead=Min(DataLeft,(size_t)SizeToRead);
    Raw.Read(Buf+ReadBufPos,CurSizeToRead);
    ReadBufPos+=CurSizeToRead;
    SizeToRead-=int(CurSizeToRead);
    if (SizeToRead>0) 
    {
      ReadBufPos=0;
      ReadBufSize=0;
      if (ReadBuffer()==0)
        return false;
    }
  }
  return SavedCRC==Raw.GetCRC50();
}
bool QuickOpen :: ReadRaw ( RawRead & Raw ) { if ( MaxBufSize - ReadBufPos < 0x100 ) { size_t DataLeft = ReadBufSize - ReadBufPos ; memcpy ( Buf , Buf + ReadBufPos , DataLeft ) ; ReadBufPos = 0 ; ReadBufSize = DataLeft ; ReadBuffer ( ) ; } const size_t FirstReadSize = 7 ; if ( ReadBufPos + FirstReadSize > ReadBufSize ) return false ; Raw . Read ( Buf + ReadBufPos , FirstReadSize ) ; ReadBufPos += FirstReadSize ; uint SavedCRC = Raw . Get4 ( ) ; uint SizeBytes = Raw . GetVSize ( 4 ) ; uint64 BlockSize = Raw . GetV ( ) ; int SizeToRead = int ( BlockSize ) ; SizeToRead -= FirstReadSize - SizeBytes - 4 ; if ( SizeToRead < 0 || SizeBytes == 0 || BlockSize == 0 ) { Loaded = false ; return false ; } while ( SizeToRead > 0 ) { size_t DataLeft = ReadBufSize - ReadBufPos ; size_t CurSizeToRead = Min ( DataLeft , ( size_t ) SizeToRead ) ; Raw . Read ( Buf + ReadBufPos , CurSizeToRead ) ; ReadBufPos += CurSizeToRead ; SizeToRead -= int ( CurSizeToRead ) ; if ( SizeToRead > 0 ) { ReadBufPos = 0 ; ReadBufSize = 0 ; if ( ReadBuffer ( ) == 0 ) return false ; } } return SavedCRC == Raw . GetCRC50 ( ) ; }
Fill RawRead object from buffer.
Fill RawRead object from buffer .
// We are close to end of buffer. // Ensure that we have enough data to read CRC and header size. // Adjust overread size bytes if any. // Invalid data. // If rest of block data crosses Buf boundary, read it in loop. // We read the entire buffer and still need more data.