Tambur MMS Library
At work I’ve been using the Tambur MMS Library to encode and decode MMS messages. Recently I encountered an unusual bug; some data parts were not being encoded correctly. The bug was related to how the MMEncoder sets the indicated data length of the image/payload.
The packaging date of the MMS Library on the website says 18th April 2005 – So for anyone using that version of the library be aware of the bug. And heres how to fix it:
MMEncoder:
protected static void encodeUintvar(ByteArrayOutputStream res, int l)
throws Exception {
//.....
for (int i = 0; i < buf.length; i++) {
if ((buf[i] & 0xFF) != 0x80)
res.write(buf[i]);
}
}
It should read:
protected static void encodeUintvar(ByteArrayOutputStream res, int l)
throws Exception {
//.....
boolean hasWrittenOnce = false;
for (int i = 0; i < buf.length; i++) {
if (hasWrittenOnce || (buf[i] & 0xFF) != 0x80) {
res.write(buf[i]);
hasWrittenOnce = true;
}
}
}
