From 68310ffdc8dc01d74fa79ddada5b85ef2233f06b Mon Sep 17 00:00:00 2001 From: Ziggy Date: Fri, 10 Jan 2025 23:20:43 +0100 Subject: [PATCH] Fixed a bug with customization string decoding, where empty state was not being handled correctly --- .../common/data/customization/CustomizationString.kt | 6 ++++-- .../data/customization/TestCustomizationString.kt | 12 +++++++++++- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/projectswg/common/data/customization/CustomizationString.kt b/src/main/java/com/projectswg/common/data/customization/CustomizationString.kt index e3b675b..b83659e 100644 --- a/src/main/java/com/projectswg/common/data/customization/CustomizationString.kt +++ b/src/main/java/com/projectswg/common/data/customization/CustomizationString.kt @@ -1,5 +1,5 @@ /*********************************************************************************** - * Copyright (c) 2024 /// Project SWG /// www.projectswg.com * + * Copyright (c) 2025 /// Project SWG /// www.projectswg.com * * * * ProjectSWG is an emulation project for Star Wars Galaxies founded on * * July 7th, 2011 after SOE announced the official shutdown of Star Wars Galaxies. * @@ -92,7 +92,9 @@ class CustomizationString : Encodable, MongoPersistable { } override fun decode(data: NetBuffer) { - val stream = CustomizationStringInputStream(data.array) + val buffer = data.array + if (buffer.isEmpty()) return + val stream = CustomizationStringInputStream(buffer) stream.read() // version - should be 0x02 val variableCount = stream.read() for (i in 0 until variableCount) { diff --git a/src/test/java/com/projectswg/common/data/customization/TestCustomizationString.kt b/src/test/java/com/projectswg/common/data/customization/TestCustomizationString.kt index 07c54e0..d904689 100644 --- a/src/test/java/com/projectswg/common/data/customization/TestCustomizationString.kt +++ b/src/test/java/com/projectswg/common/data/customization/TestCustomizationString.kt @@ -1,5 +1,5 @@ /*********************************************************************************** - * Copyright (c) 2024 /// Project SWG /// www.projectswg.com * + * Copyright (c) 2025 /// Project SWG /// www.projectswg.com * * * * ProjectSWG is an emulation project for Star Wars Galaxies founded on * * July 7th, 2011 after SOE announced the official shutdown of Star Wars Galaxies. * @@ -78,6 +78,16 @@ class TestCustomizationString { assertEquals(-100, decoded.get("/private/index_color_tattoo")) } + @Test + fun decodeEmptyCustomizationString() { + // Customization string with no variables. Can happen when creating a new character of a species that has no hair, for example. In this case, the hair customization string is empty. + val string = CustomizationString() + val encoded = string.encode() + val decoded = CustomizationString() + + assertDoesNotThrow { decoded.decode(NetBuffer.wrap(encoded)) } + } + @ParameterizedTest @MethodSource("provideRealWorldValues") fun testRealWorld(input: ByteArray) {