asLody/VirtualApp · error · java.lang.IllegalArgumentException

Invalid name:

Error message

Invalid name: 

What it means

openReadInternal validates the requested file name with FileUtils.isValidExtFilename before opening it inside the stage directory; an invalid name throws IllegalArgumentException('Invalid name: ' + name). This prevents malformed or path-like names from being used to address files in the session stage dir.

Solutions

  1. Sanitize the name with FileUtils.isValidExtFilename (or FilenameUtils) before calling openRead.
  2. Only pass file names previously returned by session.getNames().
  3. Strip path components: use new File(userInput).getName() and reject anything containing '/' or '\\'.

Example fix

// before
InputStream in = new ParcelFileDescriptor.AutoCloseInputStream(session.openRead(userInput));

// after
String name = new File(userInput).getName();
if (!FileUtils.isValidExtFilename(name)) {
    throw new IllegalArgumentException("Bad file name: " + name);
}
InputStream in = new ParcelFileDescriptor.AutoCloseInputStream(session.openRead(name));
Defensive patterns

Strategy: validation

Validate before calling

if (name == null || !FileUtils.isValidExtFilename(new File(name).getName())) {
    throw new IllegalArgumentException("Invalid session file name: " + name);
}

Type guard

boolean isValidSessionFileName(String s) {
    return s != null && !s.isEmpty() && s.equals(new File(s).getName()) && FileUtils.isValidExtFilename(s);
}

Try / catch

try (InputStream in = new ParcelFileDescriptor.AutoCloseInputStream(session.openRead(name))) {
    // read
} catch (IllegalArgumentException e) {
    // log invalid name and fall back to getNames() lookup
}

Prevention

When it happens

Trigger: Calling session.openRead(name) where name contains path separators ('../'), is null/empty, or otherwise fails isValidExtFilename.

Common situations: Reconstructing APK part names dynamically (e.g. concatenating split names) and accidentally including slashes or illegal characters; reading a file the session never wrote; passing user-supplied names straight through.

Understand the failure class

Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.

Related errors


AI-assisted analysis of asLody/VirtualApp@666fefcb5d (2026-09-09). Data as JSON: /api/errors/df9c025765dc285f. Report an issue: GitHub.

Appendix: source

Thrown at VirtualApp/lib/src/main/java/com/lody/virtual/server/pm/installer/PackageInstallerSession.java:338

            throw new IOException(e);
        }
    }

    @Override
    public ParcelFileDescriptor openRead(String name) throws RemoteException {
        try {
            return openReadInternal(name);
        } catch (IOException e) {
            throw new IllegalStateException(e);
        }
    }

    private ParcelFileDescriptor openReadInternal(String name) throws IOException {
        assertPreparedAndNotSealed("openRead");

        try {
            if (!FileUtils.isValidExtFilename(name)) {
                throw new IllegalArgumentException("Invalid name: " + name);
            }
            final File target = new File(resolveStageDir(), name);

            final FileDescriptor targetFd = Os.open(target.getAbsolutePath(), O_RDONLY, 0);
            return ParcelFileDescriptor.dup(targetFd);

        } catch (ErrnoException e) {
            throw new IOException(e);
        }
    }

    @Override
    public void removeSplit(String splitName) throws RemoteException {
        if (TextUtils.isEmpty(params.appPackageName)) {
            throw new IllegalStateException("Must specify package name to remove a split");
        }
        try {
            createRemoveSplitMarker(splitName);

View on GitHub (pinned to 666fefcb5d)