[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Bug classpath/42551] New: MetaMessage.java does not write out stored da
From: |
pdfernhout at kurtz-fernhout dot com |
Subject: |
[Bug classpath/42551] New: MetaMessage.java does not write out stored data correctly |
Date: |
30 Dec 2009 02:23:23 -0000 |
After many hours of frustration, :-) it turns out that in MetaMessage.java
[classpath] / classpath / javax / sound / midi / MetaMessage.java
http://cvs.savannah.gnu.org/viewvc/classpath/javax/sound/midi/MetaMessage.java?root=classpath&view=log
there is a function:
public void setMessage(int type, byte[] data, int length)
that includes the code snippet:
while ((length >>= 7) > 0)
{
buffer <<= 8;
buffer |= ((length & 0x7F) | 0x80);
}
This code section has a side effect of setting length to zero. But the function
later uses length in copying a data array:
// Now copy the real data.
System.arraycopy(data, 0, this.data, index, length);
Thus the passed in data is not copied because length is by then zero, leaving
the instance's own data array with zeros in those end positions.
As a consequence, MIDI events like Tempo events and TimeSignature events will
be written incorrectly to files, which can even lead to subsequent problems in
applications that read the generated MIDI files if they are not expecting zeros
there. This even caused a crash in one application I tried to use to analyze
the resulting problematical files, thus leading me to guess that the files were
malformed somehow.
A possible fix that is working for me:
// BUG FIX -- Need the original length later
int lengthCopy = length;
while ((lengthCopy >>= 7) > 0)
{
buffer <<= 8;
buffer |= ((lengthCopy & 0x7F) | 0x80);
}
This bug has apparently been in all versions of the code I looked at from the
latest 0.98 to the earliest code for that file. It would be easy to miss that
assign operator in what might just look like a test.
I hereby put those changes in the public domain.
--
Summary: MetaMessage.java does not write out stored data
correctly
Product: classpath
Version: 0.98
Status: UNCONFIRMED
Severity: major
Priority: P3
Component: classpath
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: pdfernhout at kurtz-fernhout dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=42551
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Bug classpath/42551] New: MetaMessage.java does not write out stored data correctly,
pdfernhout at kurtz-fernhout dot com <=