From bbfec1fb29bfd82970eed4154d8b25afe9b8d4a2 Mon Sep 17 00:00:00 2001 From: Kurt Date: Mon, 13 May 2024 18:14:40 -0500 Subject: [PATCH] GB: Don't read ghost slots Read count from list, instead of using the full capacity. Malformed lists (truncated via count) with ghost slots should have those ghost slots ignored. --- PKHeX.Core/PKM/Shared/PokeList1.cs | 3 ++- PKHeX.Core/PKM/Shared/PokeList2.cs | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/PKHeX.Core/PKM/Shared/PokeList1.cs b/PKHeX.Core/PKM/Shared/PokeList1.cs index 5b85675b0..3ba95c7ad 100644 --- a/PKHeX.Core/PKM/Shared/PokeList1.cs +++ b/PKHeX.Core/PKM/Shared/PokeList1.cs @@ -173,7 +173,8 @@ public static void Unpack(ReadOnlySpan input, Span output, int strin var ofsStr1 = ofsBody + (capacity * lengthBody); var ofsStr2 = ofsStr1 + (capacity * stringLength); - for (int i = 0; i < capacity; i++) + var count = Math.Min(capacity, input[0]); + for (int i = 0; i < count; i++) { var species = input[1 + i]; var body = input.Slice(ofsBody, lengthBody); diff --git a/PKHeX.Core/PKM/Shared/PokeList2.cs b/PKHeX.Core/PKM/Shared/PokeList2.cs index d886d0d65..44c262bd9 100644 --- a/PKHeX.Core/PKM/Shared/PokeList2.cs +++ b/PKHeX.Core/PKM/Shared/PokeList2.cs @@ -177,7 +177,8 @@ public static void Unpack(ReadOnlySpan input, Span output, int strin var ofsStr1 = ofsBody + (capacity * lengthBody); var ofsStr2 = ofsStr1 + (capacity * stringLength); - for (int i = 0; i < capacity; i++) + var count = Math.Min(capacity, input[0]); + for (int i = 0; i < count; i++) { var species = input[1 + i]; var body = input.Slice(ofsBody, lengthBody);