Ticket #127 (new defect)

Opened 1 year ago

Last modified 3 weeks ago

GamePacketGenerator's sendChatPacket tries to create too large a packet

Reported by: dugwyler Assigned to: nobody
Priority: normal Component: Core
Version: Latest version from repository Severity: minor
Keywords: Cc:

Description

arrayOutOfBounds error still occurs, particularly with chatbot. Oddly, the error is only with the very largest sorts of strings, which, looking over the code, makes not much sense … Sort of a note to self, unless someone else wants to check it out.

Attachments

Change History

08/05/07 06:51:22 changed by Maverick

Hmm got a stacktrace? I think this is caused because it tries to send the chat packet in one packet and not over multiple packets if necessary.

Probably just needs to send the chat packet using the sendMassiveChunkPacket() method, however sendMassiveChunkPacket() doesn't check if the packet needs to be send over multiple packets at all.

The GamePacketGenerator class probably needs a method to send packets which checks if packets are too big to use sendMassiveChunkPacket() and if not use sendReliableMessage(). All other methods using sendReliableMessage() need to use this new method to prevent problems like this in the future.

08/05/07 06:55:00 changed by Maverick

Hmm looking through the code a bit

/**
     * Sends a chat message.
     * @param messageType Type of message being sent -- public, error, etc. (0x00 to 0x09)
     * @param soundCode Number of the sound attached to this message, if any
     * @param userID For message types 0x04 and 0x05, player ID of target
     * @param message Text to send
     */
    public void sendChatPacket( byte messageType, byte soundCode, short userID, String message ){
    	if( message.length() > 243 )
    		message = message.substring(0, 242);		// (hack) Don't send more than SS can handle

        int            size = message.length() + 6;
        ByteArray      bytearray = new ByteArray( size );

        bytearray.addByte( 0x06 );          // Type byte
        bytearray.addByte( messageType );
        bytearray.addByte( soundCode );
        bytearray.addLittleEndianShort( userID );
        bytearray.addString( message );
        bytearray.addByte( 0x00 );          // Terminator

        composePacket( bytearray );
    }

It shouldn't go haywire with too large strings since it just cuts them down. Also composePacket() should be used instead of sendReliableMessage() I guess.

08/05/07 08:50:17 changed by dugwyler

The exception is thrown by ByteArray — an IndexOutOfBounds exception on the addString method. This suggests that the space allocated is not sufficient to take the entire String … but, if the String is of length X, wouldn't the space needed always be length + 6? (In other words, why is the formula "length of string + 6" sufficient when length < ~240, but not later? ByteArray is just an array of bytes with methods to add common datatypes onto its tail for easy packet construction. I would have expected an exception somewhere else, but not here … does the String contain an extra byte or two than the sum of all its characters when it gets over a certain size?)

I guess the out of bounds exception in ByteArray is just not where I would expect this error to be — I would think that the packet spec would have something to do with it … the protocol becoming irritated by too large a packet … and not just our storage medium which in the end has nothing to do with the packet. Confusing!

04/04/08 14:36:04 changed by milosh

Is this error still showing up?

04/04/08 15:37:08 changed by dugwyler

Think it does from time to time, yes. Nothing was done to fix it as far as I know.

04/05/08 04:25:29 changed by Maverick

Indeed. You can reproduce the bug by making a maximum-length size message on the devchat while the chatbots are on.

04/30/08 16:13:21 changed by milosh

  • component changed from Bots - Other to Core.

07/31/08 05:12:36 changed by milosh

  • owner set to nobody.

Going for consistency.


Add/Change #127 (GamePacketGenerator's sendChatPacket tries to create too large a packet)




Change Properties
Action