Skip to content

readFromDevice( ) in AutoDetectStream.cpp in Poco Zip cannot detect signature #1599

@mike-zhou

Description

@mike-zhou

Function AutoDetectStreamBuf::readFromDevice(char* buffer, std::streamsize length) in AutoDetectStream.cpp in Poco Zip cannot detect the Data signature 50 4B 07 08 from the these bytes:
"80 E1 50 50 4B 07 08 6B D7 9D"

In fact, any signature cannot be found by readFromDevice( ) if there a 0x50 before the signature.
Code in readFromDevice( ) can be modified as following to correct this bug:
if (_matchCnt<2)
{
if (c == ZipLocalFileHeader::HEADER[_matchCnt])
++_matchCnt;
else
{
// matchcnt was either 0 or 1 the headers have all unique chars -> safe to set to 0
if (_matchCnt == 1)
{
//save the previous byte with value ZipLocalFileHeader::HEADER[0].
buffer[tempPos++] = ZipLocalFileHeader::HEADER[0];
}
//if the current byte is not ZipLocalFileHeader::HEADER[0], then save it can clear the match count;
//otherwise, keep the match count unchanged.
if (c != ZipLocalFileHeader::HEADER[0])
{
_matchCnt = 0;
buffer[tempPos++] = static_cast(c);
}
}

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions