IOException if text file is insanely huge (>1GB)
@see https://www.filebot.net/forums/viewtopic.php?f=10&t=4364
This commit is contained in:
parent
8932eb0b2a
commit
28fa511fbe
|
@ -70,7 +70,7 @@ public class BindingsHandler extends MapOptionHandler {
|
|||
try {
|
||||
return readTextFile(f).trim();
|
||||
} catch (IOException e) {
|
||||
throw new CmdLineException(owner, e.getMessage(), e);
|
||||
throw new CmdLineException(owner, "Failed to read @file", e);
|
||||
}
|
||||
}
|
||||
return v;
|
||||
|
|
|
@ -583,12 +583,16 @@ public class MediaDetection {
|
|||
}
|
||||
|
||||
// try to grep imdb id from nfo files
|
||||
try {
|
||||
for (int imdbid : grepImdbIdFor(movieFile)) {
|
||||
Movie movie = service.getMovieDescriptor(new Movie(imdbid), locale);
|
||||
if (movie != null) {
|
||||
options.add(movie);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
debug.warning("Failed to lookup info by id: " + e);
|
||||
}
|
||||
}
|
||||
|
||||
// search by file name or folder name (NOTE: can't initialize with known options because misleading NFO files may lead to bad matches)
|
||||
|
@ -1210,20 +1214,16 @@ public class MediaDetection {
|
|||
public static Set<Integer> grepImdbIdFor(File file) throws Exception {
|
||||
Set<Integer> collection = new LinkedHashSet<Integer>();
|
||||
List<File> nfoFiles = new ArrayList<File>();
|
||||
|
||||
if (file.isDirectory()) {
|
||||
nfoFiles.addAll(listFiles(file, NFO_FILES));
|
||||
} else if (file.getParentFile() != null && file.getParentFile().isDirectory()) {
|
||||
nfoFiles.addAll(getChildren(file.getParentFile(), NFO_FILES));
|
||||
}
|
||||
|
||||
// parse ids from nfo files
|
||||
// parse IMDb IDs from NFO files
|
||||
for (File nfo : nfoFiles) {
|
||||
try {
|
||||
String text = readTextFile(nfo);
|
||||
collection.addAll(grepImdbId(text));
|
||||
} catch (Exception e) {
|
||||
debug.warning("Failed to read nfo: " + e.getMessage());
|
||||
}
|
||||
collection.addAll(grepImdbId(readTextFile(nfo)));
|
||||
}
|
||||
|
||||
return collection;
|
||||
|
@ -1242,8 +1242,9 @@ public class MediaDetection {
|
|||
|
||||
// search for id in sibling nfo files
|
||||
for (File folder : folders) {
|
||||
if (!folder.exists())
|
||||
if (!folder.exists()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
for (File nfo : getChildren(folder, NFO_FILES)) {
|
||||
String text = readTextFile(nfo);
|
||||
|
|
|
@ -195,10 +195,16 @@ public final class FileUtilities {
|
|||
}
|
||||
|
||||
public static String readTextFile(File file) throws IOException {
|
||||
long size = file.length();
|
||||
|
||||
// ignore absurdly large text files that might cause OutOfMemoryError issues
|
||||
if (size > ONE_GIGABYTE) {
|
||||
throw new IOException(String.format("Text file is too large: %s (%s)", file, formatSize(size)));
|
||||
}
|
||||
|
||||
byte[] bytes = readFile(file);
|
||||
|
||||
// check BOM
|
||||
BOM bom = BOM.detect(bytes);
|
||||
BOM bom = BOM.detect(bytes); // check BOM
|
||||
|
||||
if (bom != null) {
|
||||
return new String(bytes, bom.size(), bytes.length - bom.size(), bom.getCharset());
|
||||
|
|
Loading…
Reference in New Issue