F01 : le debut du mouvement ne s'execute plus sur le thread reseau

Injection apres PacketUtils.ensureRunningOnSameThread (INVOKE, shift AFTER) au lieu de HEAD ;
garde isSameThread dans Garde. Test de bytecode MixinsThreadTest (rouge avant), 101 tests.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Cette révision appartient à :
gastineltetClaude Opus 5.5 a révisé 2026-10-14 08:30:34 +02:00
1 Parent c45ec6df7b
révision f69348b08b
5 fichiers modifiés
+196 -1

Aucun fichier ne correspond à votre recherche

+94
Voir le fichier
@@ -0,0 +1,94 @@
package com.gastinelgarde;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import org.junit.jupiter.api.Test;
import org.objectweb.asm.ClassReader;
import org.objectweb.asm.tree.AnnotationNode;
import org.objectweb.asm.tree.ClassNode;
import org.objectweb.asm.tree.MethodNode;
/**
* F01 (audit 2026-10-14) : une méthode handle* de ServerGamePacketListenerImpl commence par
* PacketUtils.ensureRunningOnSameThread. Sur le thread réseau, cet appel replanifie le paquet puis lève une
* exception : tout ce qui est injecté AVANT s'exécute donc deux fois (Netty puis serveur).
*
* On lit le bytecode du mixin (ASM) : charger la classe d'un mixin directement est interdit par Mixin.
*/
class MixinsThreadTest {
static final String ENSURE = "Lnet/minecraft/network/protocol/PacketUtils;ensureRunningOnSameThread("
+ "Lnet/minecraft/network/protocol/Packet;Lnet/minecraft/network/PacketListener;"
+ "Lnet/minecraft/server/level/ServerLevel;)V";
record Injection(String methode, String annotation, List<String> cibles, AnnotationNode at) { }
static ClassNode lire(String classe) throws Exception {
try (InputStream in = MixinsThreadTest.class.getClassLoader()
.getResourceAsStream(classe.replace('.', '/') + ".class")) {
assertNotNull(in, classe);
ClassNode n = new ClassNode();
new ClassReader(in).accept(n, ClassReader.SKIP_CODE);
return n;
}
}
@SuppressWarnings("unchecked")
static Object valeur(AnnotationNode a, String nom) {
if (a == null || a.values == null) return null;
for (int i = 0; i + 1 < a.values.size(); i += 2) {
if (nom.equals(a.values.get(i))) return a.values.get(i + 1);
}
return null;
}
@SuppressWarnings("unchecked")
static List<Injection> injections(ClassNode n) {
List<Injection> sortie = new ArrayList<>();
for (MethodNode m : n.methods) {
List<AnnotationNode> toutes = new ArrayList<>();
if (m.visibleAnnotations != null) toutes.addAll(m.visibleAnnotations);
if (m.invisibleAnnotations != null) toutes.addAll(m.invisibleAnnotations);
for (AnnotationNode a : toutes) {
if (!a.desc.startsWith("Lorg/spongepowered/asm/mixin/injection/")) continue;
Object cibles = valeur(a, "method");
Object at = valeur(a, "at");
if (at instanceof List<?> l) at = l.isEmpty() ? null : l.get(0);
sortie.add(new Injection(m.name, a.desc, cibles == null ? List.of() : (List<String>) cibles,
(AnnotationNode) at));
}
}
return sortie;
}
static boolean visePaquet(Injection i) {
return i.cibles().stream().anyMatch(c -> c.startsWith("handle"));
}
@Test
void F01_aucune_injection_HEAD_dans_un_handle() throws Exception {
for (String classe : new String[] {"com.gastinelgarde.mixin.MovePacketMixin", "com.gastinelgarde.mixin.RiptideMoveMixin"}) {
for (Injection i : injections(lire(classe))) {
if (!visePaquet(i) || i.at() == null) continue;
assertFalse("HEAD".equals(valeur(i.at(), "value")),
classe + "." + i.methode() + " : HEAD d'un handle* = exécuté aussi sur le thread réseau");
}
}
}
@Test
void F01_debut_du_mouvement_apres_ensureRunningOnSameThread() throws Exception {
Injection avant = injections(lire("com.gastinelgarde.mixin.MovePacketMixin")).stream()
.filter(i -> i.methode().equals("gastinelgarde$avantMouvement")).findFirst().orElseThrow();
assertEquals("INVOKE", valeur(avant.at(), "value"));
assertEquals(ENSURE, valeur(avant.at(), "target"));
Object shift = valeur(avant.at(), "shift");
assertTrue(shift instanceof String[] s && s.length == 2 && "AFTER".equals(s[1]), "shift = AFTER");
}
}
+52
Voir le fichier
@@ -0,0 +1,52 @@
package com.gastinelgarde.core;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import java.util.List;
import java.util.UUID;
import org.junit.jupiter.api.Test;
/**
* Preuves de l'audit 2026-10-14 (audit/tests-proposes/AuditFaillesTest.java), intégrées une par une avec la
* correction de chaque faille : les assertions « BYPASS » et « FAUX_POSITIF » ont été inversées une fois la
* faille corrigée. Chaque test porte l'identifiant de la faille (audit/02-failles-detection.md).
*/
class AuditFaillesTest {
private final GardeConfig cfg = new GardeConfig();
private final Moteur moteur = new Moteur(cfg);
private final UUID j = UUID.randomUUID();
static EtatMouvement mv(double dxz, double dy, int ticks, boolean solServeur, boolean sprint) {
return new EtatMouvement(dxz, dy, ticks, solServeur, solServeur, sprint, false, false, 0, 0, false, false);
}
static boolean contient(List<Verdict> v, Controle c) {
return v.stream().anyMatch(x -> x.controle() == c);
}
// ---------------------------------------------------------------- F01
/**
* Ce que coûtait le HEAD du mixin exécuté sur les deux threads : un joueur honnête vu à 40 paquets/s. La
* correction (injection après ensureRunningOnSameThread) est vérifiée sur le bytecode : MixinsThreadTest.
*/
@Test
void F01_un_paquet_compte_une_fois_est_honnete_deux_fois_faux_positif() {
boolean simple = false;
UUID a = UUID.randomUUID();
for (long t = 0; t < 10_000; t += 50) {
if (contient(moteur.paquetMouvement(a, t, EtatJoueur.normal()), Controle.TIMER)) simple = true;
}
assertFalse(simple, "20 paquets/s comptés une fois : aucune infraction");
boolean double_ = false;
UUID b = UUID.randomUUID();
for (long t = 0; t < 10_000; t += 50) {
moteur.paquetMouvement(b, t, EtatJoueur.normal());
if (contient(moteur.paquetMouvement(b, t + 1, EtatJoueur.normal()), Controle.TIMER)) double_ = true;
}
assertTrue(double_, "20 paquets/s comptés deux fois = 40/s : c'est pourquoi le mixin ne doit compter qu'une fois");
}
}