Skip to content

Commit

Permalink
validate nickname characters within gen4 (#4382)
Browse files Browse the repository at this point in the history
pkmnclassic has recently had some pokemon traded that cause game
crashes when viewing the pokemon's information, or when trying to
remove the pokemon for these boxes. most of these pokemon were reported
legal by pkhex however. this fixes the biggest use of these we've seen
actively traded (some of the other checks require more validation, as
they seemed to be buggy, we intend to validate those & send more PRs if
needed).

this check effectively covers "NULL Bytes" within the trainers name,
or the pokemon's nickname. We have attached an example pk4 that was
traded through our service that exhibits this issue, a couple notes:

- Generation 5+ seem to not be affected and replace character names with
  '?'
- Not all screens crash inside of Generation 4, the big ones our users
  noticed were viewing the pokemons information, and removal from the
  boxes.
- I also got a crash in pokemon ranch, but my testing setup was pretty
  hacky, and I'm not confident it wasn't something else, but we know
  it's potentially possible.

- We check for the terminator character '\uffff' which the pkhex string
  converter inserts implicitly when encountering an invalid character,
  but the actual underlying character when performing a hex dump is
  `\0`.
  • Loading branch information
Mythra authored Nov 12, 2024
1 parent fced599 commit f2a6abb
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
5 changes: 5 additions & 0 deletions PKHeX.Core/Legality/Verifiers/NicknameVerifier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ public override void Verify(LegalityAnalysis data)
return;
}
nickname = nickname[..len];
if (nickname.Contains('\uffff') && pk is { Format: 4 })
{
data.AddLine(GetInvalid(LNickInvalidChar));
return;
}

var enc = data.EncounterOriginal;
if (enc is ILangNicknamedTemplate n)
Expand Down
5 changes: 5 additions & 0 deletions PKHeX.Core/Legality/Verifiers/TrainerNameVerifier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ public override void Verify(LegalityAnalysis data)
return;
}
trainer = trainer[..len];
if (trainer.Contains('\uffff') && pk is { Format: 4 })
{
data.AddLine(GetInvalid("Trainer Name: Unkown Character"));
return;
}

if (IsOTNameSuspicious(trainer))
{
Expand Down

0 comments on commit f2a6abb

Please sign in to comment.