Skip to content

Commit

Permalink
Skip remaining unsupported versioned fields
Browse files Browse the repository at this point in the history
  • Loading branch information
Walkyst committed Dec 15, 2022
1 parent b94abef commit e2fea31
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -266,15 +266,22 @@ public void encodeTrack(MessageOutput stream, AudioTrack track) throws IOExcepti

@Override
public DecodedTrackHolder decodeTrack(MessageInput stream) throws IOException {
DataInput input = stream.nextMessage();
DataInputStream input = stream.nextMessage();
if (input == null) {
return null;
}

int version = (stream.getMessageFlags() & TRACK_INFO_VERSIONED) != 0 ? (input.readByte() & 0xFF) : 1;

AudioTrackInfo trackInfo = new AudioTrackInfo(input.readUTF(), input.readUTF(), input.readLong(), input.readUTF(),
input.readBoolean(), version >= 2 ? DataFormatTools.readNullableText(input) : null);
AudioTrackInfo trackInfo = new AudioTrackInfo(
input.readUTF(),
input.readUTF(),
input.readLong(),
input.readUTF(),
input.readBoolean(),
version >= 2 ? DataFormatTools.readNullableText(input) : null
);
stream.skipRemainingVersionedFields(input);
AudioTrack track = decodeTrackDetails(trackInfo, input);
long position = input.readLong();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.sedmelluq.discord.lavaplayer.tools.io;

import java.io.DataInput;
import java.io.DataInputStream;
import java.io.IOException;
import java.io.InputStream;
Expand Down Expand Up @@ -32,7 +31,7 @@ public MessageInput(InputStream inputStream) {
* marker.
* @throws IOException On IO error
*/
public DataInput nextMessage() throws IOException {
public DataInputStream nextMessage() throws IOException {
int value = dataInputStream.readInt();
messageFlags = (int) ((value & 0xC0000000L) >> 30L);
messageSize = value & 0x3FFFFFFF;
Expand Down Expand Up @@ -65,4 +64,24 @@ public void skipRemainingBytes() throws IOException {

messageSize = 0;
}

public void skipRemainingVersionedFields(DataInputStream input) throws IOException {
CountingInputStream counter = new CountingInputStream(input);
DataInputStream in = new DataInputStream(counter);
in.mark(in.available());
int lastByte;
while ((lastByte = in.read()) != -1) {
if (lastByte > 1) {
in.reset();
in.skipBytes((int) (counter.getByteCount()) - 2);
break;
} else if (lastByte == 1) {
in.skipBytes(in.readUnsignedShort());
} else if (lastByte == 0) {
// Skip zero byte
} else {
break;
}
}
}
}

0 comments on commit e2fea31

Please sign in to comment.