MuntashirAkon/AppManager · error

Error! Buffer overflow on main_jar_path.\n

Error message

Error! Buffer overflow on main_jar_path.\n

What it means

Guard after snprintf in main(): building the path for the main jar (TMP_PATH plus main_jar_name) overflowed its 512-byte main_jar_path buffer. Like the exec_jar_path check, it aborts early to avoid using a truncated or non-terminating path; the faulting input is an over-long main_jar_name argument.

Source

Thrown at app/src/main/cpp/run_server.c:114

    // Validate debug and bgrun
    if ((strcmp(debug, "0") != 0 && strcmp(debug, "1") != 0)) {
        fprintf(stderr, "Error! debug must be either 0 or 1.\n");
        return 1;
    }

    // /data/local/tmp/am.jar
    char exec_jar_path[512];
    if (snprintf(exec_jar_path, sizeof(exec_jar_path), "%s/%s", TMP_PATH, am_jar_name) >=
        sizeof(exec_jar_path)) {
        fprintf(stderr, "Error! Buffer overflow on exec_jar_path.\n");
        return 1;
    }

    // /data/local/tmp/main.jar
    char main_jar_path[512];
    if (snprintf(main_jar_path, sizeof(main_jar_path), "%s/%s", TMP_PATH, main_jar_name) >=
        sizeof(main_jar_path)) {
        fprintf(stderr, "Error! Buffer overflow on main_jar_path.\n");
        return 1;
    }

    // Prioritized list of fallback source paths
    char am_jar_fallbacks[4][512];
    snprintf(am_jar_fallbacks[0], sizeof(am_jar_fallbacks[0]), "/sdcard/Android/data/%s/cache/%s",
             app_id,
             am_jar_name);
    snprintf(am_jar_fallbacks[1], sizeof(am_jar_fallbacks[1]),
             "/storage/emulated/%s/Android/data/%s/cache/%s",
             user_id, app_id, am_jar_name);
    snprintf(am_jar_fallbacks[2], sizeof(am_jar_fallbacks[2]), "/sdcard/AppManager/%s",
             am_jar_name);
    snprintf(am_jar_fallbacks[3], sizeof(am_jar_fallbacks[3]), "/storage/emulated/%s/AppManager/%s",
             user_id,
             am_jar_name);

    char main_jar_fallbacks[4][512];

View on GitHub (pinned to 0152f468fc)

Solutions

  1. Use a shorter main_jar_name
  2. Bump the buffer to PATH_MAX in run_server.c and rebuild
  3. Enforce a filename length limit (e.g. <= 256 chars) in the app before launching

Example fix

// before
char main_jar_path[512];
// after
char main_jar_path[PATH_MAX];
Defensive patterns

Strategy: validation

Validate before calling

String path = TMP_PATH + "/" + mainJarName;
if (path.length() >= 512)
    throw new IllegalArgumentException("main_jar_name too long (path would exceed 512 bytes)");

Prevention

When it happens

Trigger: len(TMP_PATH) + 1 + strlen(main_jar_name) >= 512.

Common situations: Overly long main jar filename or a long custom TMP_PATH; directory components embedded in main_jar_name pushing the length over the limit.

Understand the failure class

Background: "value must be between 0 and 1" / "out of range" / "must not be negative" errors: fixing range-validation failures across open-source libraries — this error's family across 42 libraries.

Related errors


AI-assisted analysis of MuntashirAkon/AppManager@0152f468fc (2026-09-12). Data as JSON: /api/errors/0fb8c5d5470ff9a7. Report an issue: GitHub.