[jboss-jira] [JBoss JIRA] Created: (JBSER-93) StringUtil.saveString()/.readString() length bug

Andrei Chiritescu (JIRA) jira-events at lists.jboss.org
Tue Feb 13 12:37:31 EST 2007


StringUtil.saveString()/.readString() length bug 
-------------------------------------------------

                 Key: JBSER-93
                 URL: http://jira.jboss.com/jira/browse/JBSER-93
             Project: JBoss Serialization
          Issue Type: Bug
            Reporter: Andrei Chiritescu
         Assigned To: Clebert Suconic


In the StringUtil.saveString() method the length is saved using the following code :
<code>
    if (len>0xffff)
    {
        out.writeBoolean(true); // the size is bigger than a short value
        out.writeLong(len);
    }
    else
    {
        out.writeBoolean(false);
        out.writeShort((short)len);
    }
</code>

.... and in the StringUtil.readString() the length is read using :
<code>
    boolean isLong = input.readBoolean();
    if (isLong)
    {
        size = input.readLong();
    }
    else
    {
        size = input.readShort();
    }
</code>

The problem is with string that have a length between '7FFF' and 'FFFF' - they will have the length stored as a short but when the length will be read for deserialization readShort() will return a negative number. 

To fix this you'll have to either use 7FFF instead of FFFF in the saveString() when comparing or use 'size = input.readUnsignedShort();' when reading the length in the readString().


-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://jira.jboss.com/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        



More information about the jboss-jira mailing list