Skip to content

Commit b7d1d9d

Browse files
committed
Limit lenght of sound name
Fixes #2366
1 parent 2105c5c commit b7d1d9d

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

projects/common/src/main/java/dan200/computercraft/shared/peripheral/speaker/SpeakerPeripheral.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,11 @@ public abstract class SpeakerPeripheral implements IPeripheral {
6262
*/
6363
public static final int SAMPLE_RATE = 48000;
6464

65+
/**
66+
* The maximum length of a {@link ResourceLocation} played by {@link #playSound(ILuaContext, String, Optional, Optional)}.
67+
*/
68+
private static final int MAX_SOUND_LENGTH = 512;
69+
6570
private final UUID source = UUID.randomUUID();
6671
private final AttachedComputerSet computers = new AttachedComputerSet();
6772

@@ -253,8 +258,10 @@ public final boolean playSound(ILuaContext context, String name, Optional<Double
253258
var volume = (float) clampVolume(checkFinite(1, volumeA.orElse(1.0)));
254259
var pitch = (float) checkFinite(2, pitchA.orElse(1.0));
255260

261+
if (name.length() > MAX_SOUND_LENGTH) throw new LuaException("bad argument #1 (sound name is too long)");
262+
256263
var identifier = ResourceLocation.tryParse(name);
257-
if (identifier == null) throw new LuaException("Malformed sound name '" + name + "' ");
264+
if (identifier == null) throw new LuaException("bad argument #1 (malformed sound name)");
258265

259266
// Prevent playing music discs.
260267
var soundEvent = PlatformHelper.get().tryGetRegistryObject(Registries.SOUND_EVENT, identifier);

0 commit comments

Comments
 (0)