sanoopsivan / jsmpp

Automatically exported from code.google.com/p/jsmpp
Apache License 2.0
0 stars 0 forks source link

Incorrect decoding of short optional attributes #8

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Send a messages with a positive short (2-byte) attribute value with a
negative LSB
2. Check received value - it will be negative

What is the expected output? What do you see instead?
The received value is supposed to be the same as sent one

What version of the product are you using? On what operating system?
2.0b5

Please provide any additional information below.
This is an obvious bug in OctetUtils.bytesToShort(byte[] bytes, int offset)
(missed & 0xff) ; A similar code in OctetUtils.bytesToInt is correct

Original issue reported on code.google.com by igor.sko...@gmail.com on 30 Oct 2008 at 8:09

GoogleCodeExporter commented 8 years ago
Can you give me the exact examples of the error. Code will be nice. I created 
some 
test for the OctetUtil (attached) but there is no problem found.

Original comment by uuda...@gmail.com on 30 Oct 2008 at 8:36

GoogleCodeExporter commented 8 years ago
package org.jsmpp.util;

import junit.framework.TestCase;

public class OctetItilsTest extends TestCase{
    public void testShortEncode() {
        assertEquals(0x1D4, OctetUtil.bytesToShort(new byte[] {1, (byte)0xD4}, 0));
    }

}

junit.framework.AssertionFailedError: expected:<468> but was:<-44>
    at junit.framework.Assert.fail(Assert.java:47)
    at junit.framework.Assert.failNotEquals(Assert.java:280)
    at junit.framework.Assert.assertEquals(Assert.java:64)
    at junit.framework.Assert.assertEquals(Assert.java:198)
    at junit.framework.Assert.assertEquals(Assert.java:204)
    at org.jsmpp.util.OctetItilsTest.testShortEncode(OctetItilsTest.java:7)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at junit.framework.TestCase.runTest(TestCase.java:164)
    at junit.framework.TestCase.runBare(TestCase.java:130)
    at junit.framework.TestResult$1.protect(TestResult.java:106)
    at junit.framework.TestResult.runProtected(TestResult.java:124)
    at junit.framework.TestResult.run(TestResult.java:109)
    at junit.framework.TestCase.run(TestCase.java:120)
    at
org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestR
eference.java:130)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner
.java:460)
    at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner
.java:673)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
    at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.jav
a:196)

Original comment by igor.sko...@gmail.com on 30 Oct 2008 at 8:50

GoogleCodeExporter commented 8 years ago
A more prominent version:
assertEquals(0x1D4, 
OctetUtil.bytesToShort(OctetUtil.shortToBytes((short)0x1D4), 0));
with the same result:

junit.framework.AssertionFailedError: expected:<468> but was:<-44>

Original comment by igor.sko...@gmail.com on 30 Oct 2008 at 8:59

GoogleCodeExporter commented 8 years ago
Thanks a lot Igor. The bug has been fixed. The fixed source has been attached 
or you 
can get it from the repository.

Original comment by uuda...@gmail.com on 30 Oct 2008 at 9:05

Attachments:

GoogleCodeExporter commented 8 years ago
Thank you!

Original comment by igor.sko...@gmail.com on 30 Oct 2008 at 9:08