void Gunzip::ProcessPrestreamHeader() { m_length = 0; m_crc.Restart(); byte buf[6]; byte b, flags; if (m_inQueue.Get(buf, 2)!=2) throw HeaderErr(); if (buf[0] != MAGIC1 || buf[1] != MAGIC2) throw HeaderErr(); if (!m_inQueue.Skip(1)) throw HeaderErr(); // skip extra flags if (!m_inQueue.Get(flags)) throw HeaderErr(); if (flags & (ENCRYPTED | CONTINUED)) throw HeaderErr(); if (m_inQueue.Skip(6)!=6) throw HeaderErr(); // Skip file time, extra flags and OS type if (flags & EXTRA_FIELDS) // skip extra fields { word16 length; if (m_inQueue.GetWord16(length, LITTLE_ENDIAN_ORDER) != 2) throw HeaderErr(); if (m_inQueue.Skip(length)!=length) throw HeaderErr(); } if (flags & FILENAME) // skip filename do if(!m_inQueue.Get(b)) throw HeaderErr(); while (b); if (flags & COMMENTS) // skip comments do if(!m_inQueue.Get(b)) throw HeaderErr(); while (b); }
void Gunzip::ProcessHeader() { byte buf[6]; byte b, flags; if (inQueue.Get(buf, 2)!=2) goto error; if (buf[0] != MAGIC1 || buf[1] != MAGIC2) goto error; if (!inQueue.Skip(1)) goto error; // skip extra flags if (!inQueue.Get(flags)) goto error; if (flags & (ENCRYPTED | CONTINUED)) goto error; if (inQueue.Skip(6)!=6) goto error; // Skip file time, extra flags and OS type if (flags & EXTRA_FIELDS) // skip extra fields { word16 length; if(!inQueue.GetShort(length, false)) goto error; if (inQueue.Skip(length)!=length) goto error; } if (flags & FILENAME) // skip filename do if(!inQueue.Get(b)) goto error; while (b); if (flags & COMMENTS) // skip comments do if(!inQueue.Get(b)) goto error; while (b); inQueue.TransferTo(inflater); state = PROCESS_BODY; return; error: throw HeaderErr(); }