poco icon indicating copy to clipboard operation
poco copied to clipboard

Base64Decoder&Base64Encoder BUG

Open liangyaozhan opened this issue 7 years ago • 2 comments

Actual behavior

Base64Decoder&Base64Encoder not work correctly.

POCO version

any version <=1.9.0

Compiler and version

gcc 版本 8.2.0 (GCC)

Operating system and version

4.17.12-arch1-1-ARCH #1 SMP PREEMPT Fri Aug 3 07:16:41 UTC 2018 x86_64 GNU/Linux

Other relevant information

this bug can be fix Base64Decoder.cpp: int Base64DecoderBuf::readFromDevice() , can be fix like this way: _group[0] = (_pInEncoding[buffer[0]] << 2) | ((_pInEncoding[buffer[1]] >> 4) & 0x03); _group[1] = ((_pInEncoding[buffer[1]] << 4) & 0xF0) | ((_pInEncoding[buffer[2]]>> 2)&0x0f) ; _group[2] = ((_pInEncoding[buffer[2]] << 6)&0xC0) | (_pInEncoding[buffer[3]] & 0x3f);

Base64Encoder.cpp:


int Base64EncoderBuf::writeToDevice(char c)
{
	static const int eof = std::char_traits<char>::eof();

	_group[_groupLength++] = (unsigned char) c;
	if (_groupLength == 3)
	{
		unsigned char idx;
		idx = (0xfc&_group[0]) >> 2;
		if (_buf.sputc(_pOutEncoding[idx]) == eof) return eof;
		idx = ((_group[0] & 0x03) << 4) | ((_group[1]&0xf0) >> 4);
		if (_buf.sputc(_pOutEncoding[idx]) == eof) return eof;
		idx = ((_group[1] & 0x0F) << 2) | ((_group[2]&0xc0) >> 6);
		if (_buf.sputc(_pOutEncoding[idx]) == eof) return eof;
		idx = _group[2] & 0x3F;
		if (_buf.sputc(_pOutEncoding[idx]) == eof) return eof;
		_pos += 4;
		if (_lineLength > 0 && _pos >= _lineLength)
		{
			if (_buf.sputc('\r') == eof) return eof;
			if (_buf.sputc('\n') == eof) return eof;
			_pos = 0;
		}
		_groupLength = 0;
	}
	return charToInt(c);
}


int Base64EncoderBuf::close()
{
	static const int eof = std::char_traits<char>::eof();

	if (sync() == eof) return eof;
	if (_groupLength == 1)
	{
		_group[1] = 0;
		unsigned char idx;
		idx = (0xfc&_group[0]) >> 2;
		if (_buf.sputc(_pOutEncoding[idx]) == eof) return eof;
		idx = ((_group[0] & 0x03) << 4) | ((_group[1]&0xf0) >> 4);
		if (_buf.sputc(_pOutEncoding[idx]) == eof) return eof;
		if (!(_options & BASE64_NO_PADDING))
		{
			if (_buf.sputc('=') == eof) return eof;
			if (_buf.sputc('=') == eof) return eof;
		}
	}
	else if (_groupLength == 2)
	{
		_group[2] = 0;
		unsigned char idx;
		idx = (0xfc&_group[0]) >> 2;
		if (_buf.sputc(_pOutEncoding[idx]) == eof) return eof;
		idx = ((_group[0] & 0x03) << 4) | ((_group[1]&0xf0) >> 4);
		if (_buf.sputc(_pOutEncoding[idx]) == eof) return eof;
		idx = ((_group[1] & 0x0F) << 2) |  ((_group[2]&0xc0) >> 6);
		if (_buf.sputc(_pOutEncoding[idx]) == eof) return eof;
		if (!(_options & BASE64_NO_PADDING))
		{
			if (_buf.sputc('=') == eof) return eof;
		}
	}
	_groupLength = 0;
	return _buf.pubsync();
}

liangyaozhan avatar Sep 29 '18 02:09 liangyaozhan

This issue is stale because it has been open for 365 days with no activity.

github-actions[bot] avatar Jun 24 '22 03:06 github-actions[bot]

need more information (best is code demonstrating the problem)

aleks-f avatar Jun 24 '22 09:06 aleks-f

This issue is stale because it has been open for 365 days with no activity.

github-actions[bot] avatar Nov 26 '23 02:11 github-actions[bot]

This issue was closed because it has been inactive for 60 days since being marked as stale.

github-actions[bot] avatar Jan 25 '24 02:01 github-actions[bot]