#15 GSM 7 bits encoder/decoder bug

open
Abhik Sarkar
None
5
2012-10-26
2008-02-27
No

For the class org.smpp.charset.Gsm7BitCharset contained into the OpenSMPP distribution 2.0.

It seems to affect both the encoder and the decoder.

Actually when encoding, the test code of the overlooking loop is
'while (cb.hasRemaining() && bb.hasRemaining()) { [...] }'
Therefore, when for the general case the ByteBuffer of the characters encoded (bb) runs out before the buffer of the characters to encode when encoding with default characters map, only part of the characters to encode is translated, and it ends up with an exception.

The same thing occurs when decoding GSM7bit encoded ByteBuffer

I suggest to replace within the encoder 'while (cb.hasRemaining() && bb.hasRemaining()) { [...] }' with
'while ( cb.hasRemaining() ) {
if( !bb.hasRemaining() ) {
cr = CoderResult.OVERFLOW;
break;
}
[...] }' and the exception does not occur anymore.

Discussion