mojira.dev
MC-306677

Setting an integer debug property to a value that is not an integer causes the game to crash before starting

Setting -DMC_DEBUG_FAKE_LATENCY_MS or -DMC_DEBUG_FAKE_JITTER_MS to a value that is not an integer (and enabling -DMC_DEBUG_ENABLED) causes the game to crash before it even starts. No crash report is created, since the crash happens before the game’s crash handling mechanism is initiated.

How to reproduce:

  1. Run the game or a server with the following JVM properties: -DMC_DEBUG_ENABLED -DMC_DEBUG_FAKE_LATENCY_MS=teststring
    -> ❌ The game does not start and a crash window appears in the launcher. A server started this way prints an exception and exits.

Expected result:

Setting an integer debug property to a non-integer value would not affect anything and the game would start and act as if the malformed value has not been set.

Observed result:

Setting an integer debug property to a non-integer value causes the game to crash before even starting properly.

Stack trace:

Exception in thread "ServerMain" java.lang.ExceptionInInitializerError
        at net.minecraft.server.Main.main(Main.java:68)
        at net.minecraft.bundler.Main.lambda$run$0(Main.java:54)
        at java.base/java.lang.Thread.run(Thread.java:1474)
Caused by: java.lang.NumberFormatException: For input string: "teststring"
        at java.base/java.lang.NumberFormatException.forInputString(NumberFormatException.java:67)
        at java.base/java.lang.Integer.parseInt(Integer.java:565)
        at java.base/java.lang.Integer.parseInt(Integer.java:662)
        at net.minecraft.SharedConstants.debugIntValue(SharedConstants.java:100)
        at net.minecraft.SharedConstants.<clinit>(SharedConstants.java:186)
        ... 3 more

Code analysis:

This code analysis uses 26.1-snapshot-10’s code, decompiled using Vineflower.

When the net.minecraft.SharedConstants class is accessed by the JVM for the first time (really early on), the following static fields are initialized:

public static final int DEBUG_FAKE_LATENCY_MS = debugIntValue("FAKE_LATENCY_MS");
public static final int DEBUG_FAKE_JITTER_MS = debugIntValue("FAKE_JITTER_MS");

Both of these fields run the debugIntValue(String) method, which is shown below:

private static int debugIntValue(final String name) {
  if (!DEBUG_ENABLED) {
     return 0;
  } else {
     String prefixedName = prefixDebugFlagName(name);
     if (DEBUG_PRINT_PROPERTIES) {
        System.out.println("Debug property available: " + prefixedName + ": int");
     }

     return Integer.parseInt(System.getProperty(prefixedName, "0"));
  }
}

The System.getProperty call returns a string, which is then passed into the Integer.parseInt method, without checking if it’s actually an integer first. Integer.parseInt throws a NumberFormatException when its argument is not an integer, and therefore setting those debug properties to non-integer values causes this exception.

Comments 0

No comments.

[Mod] ManosSef

(Unassigned)

Unconfirmed

1.21.11, 26.1 Snapshot 10

Retrieved