[QFJ-631] Wrong checksum calculation in "quickfix.Field.getTotal()" Created: 31/Aug/11  Updated: 02/Apr/15  Resolved: 09/Jun/14

Status: Closed
Project: QuickFIX/J
Component/s: Engine
Affects Version/s: 1.5.0
Fix Version/s: 1.6.0

Type: Bug Priority: Major
Reporter: John Assignee: amichair
Resolution: Fixed Votes: 0
Labels: QuickfixJ, encoding
Environment:

Java


Issue Links:
Relates
relates to QFJ-38 FIX Message support double-byte charset. Closed
relates to QFJ-382 Foreign Language Support - Multibyte ... Closed

 Description   

The "quickfix.Field.getTotal()" method computes the checksum with the following code:
for (int i = 0; i < this.data.length(); ++i)

{ sum += this.data.charAt(i); }

A problem arises if the returned character is written with more than 1 character.
The checksum calculation must be done on "byte"s (the Quickfix specification)

I wrote a correction:
byte[] bytes = null;
try {
bytes = this.data.getBytes(CharsetSupport.getCharset());
for (int i = 0; i < bytes.length; ++i)

{ sum += (((int) bytes[i]) & 0x00FF); }

} catch (UnsupportedEncodingException e)

{ throw new RuntimeException(e); }

 Comments   
Comment by John [ 31/Aug/11 ]

The same applies to "quickfix.Message":

private int checkSum(String s) {
final int offset = s.lastIndexOf("\00110=");
int sum = 0;
for (int i = 0; i < offset; i++)

{ sum += s.charAt(i); <----------- }

return (sum + 1) % 256;
}

Generated at Sat Nov 23 08:30:01 UTC 2024 using JIRA 7.5.2#75007-sha1:9f5725bb824792b3230a5d8716f0c13e296a3cae.