Skip to content

Fix Lavalink sometimes not decoding tracks properly

Mateusz Brawański requested to merge github/fork/uwx/patch-96 into master

Created by: uwx

Summary

Fixes DSharpPlus.Lavalink not being able to handle some tracks, triggering an exception on track finish.

Details

Lavaplayer (and thus Lavalink) encodes tracks with DataOutputStream, which is a Very Bad Idea™️ for interoperability (as was once said by Jon Skeet himself). The main problem caused by this is the need to swap the endianness when reading data provided by it, which the lib accounts for. However, one sneakier problem is that the strings are not encoded with real UTF-8, which the lib does not account for. This doesn't cause any problems when the tracks being decoded only contain characters in the range \u0001 to \u007F, so it went unnoticed. The solution was to implement my own decoder for Java's arcane UTF-8, since copying and pasting code from the JDK would be a licensing nightmare.

Changes proposed

  • Rewrite LavalinkUtilities.DecodeTrack
  • Create a JavaBinaryReader class designed to handle data from DataOutputStream

Notes

This was actually a pretty fun bug to fix. I've tested the decoding with normal strings, strings containing special characters, and the strings reported to cause issues by thegiggitybyte#8099 on Discord.

Merge request reports

Loading