8283190: Improve MIDI processing

Reviewed-by: yan
Backport-of: e0329eb343661edd5066deb6ae5d99a742135831
This commit is contained in:
Aleksei Voitylov 2022-05-25 09:18:54 +00:00 committed by Yuri Nesterenko
parent 308e2d484a
commit a3d5c748f8

View File

@ -380,6 +380,11 @@ final class SMFParser {
case 0xF7:
// sys ex
int sysexLength = (int) readVarInt();
if (sysexLength < 0 || sysexLength > trackLength - pos) {
throw new InvalidMidiDataException("Message length is out of bounds: "
+ sysexLength);
}
byte[] sysexData = new byte[sysexLength];
read(sysexData);
@ -392,8 +397,8 @@ final class SMFParser {
// meta
int metaType = readUnsigned();
int metaLength = (int) readVarInt();
if (metaLength < 0) {
throw new InvalidMidiDataException("length out of bounds: "
if (metaLength < 0 || metaLength > trackLength - pos) {
throw new InvalidMidiDataException("Message length is out of bounds: "
+ metaLength);
}
final byte[] metaData;