Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Base64Decoder&Base64Encoder BUG #2484

Closed
liangyaozhan opened this issue Sep 29, 2018 · 4 comments
Closed

Base64Decoder&Base64Encoder BUG #2484

liangyaozhan opened this issue Sep 29, 2018 · 4 comments
Labels
Milestone

Comments

@liangyaozhan
Copy link

liangyaozhan commented Sep 29, 2018

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();
}

@github-actions
Copy link

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

@github-actions github-actions bot added the stale label Jun 24, 2022
@aleks-f
Copy link
Member

aleks-f commented Jun 24, 2022

need more information (best is code demonstrating the problem)

@aleks-f aleks-f added this to the Unspecified milestone Jun 24, 2022
@github-actions github-actions bot removed the stale label Jun 25, 2022
Copy link

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

@github-actions github-actions bot added the stale label Nov 26, 2023
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants