AI REVIEWED
Module: cli
Files: All commands
Severity: High
Summary
Files.readString() loads the entire file into heap. No file size check is performed. A 1GB+ file causes OutOfMemoryError.
Suggested Fix
private static final long MAX_FILE_SIZE = 100 * 1024 * 1024; // 100MB
long size = Files.size(inputFile.toPath());
if (size > MAX_FILE_SIZE) {
throw new IOException("File exceeds maximum size (" + (MAX_FILE_SIZE / 1024 / 1024) + "MB): " + inputFile);
}