forked from I2P_Developers/i2p.i2p
* i2psnark:
- Fix NPE after create file failure - Sanitize more characters in file names
This commit is contained in:
@ -425,9 +425,18 @@ public class SnarkManager implements Snark.CompleteListener {
|
|||||||
FileInputStream fis = null;
|
FileInputStream fis = null;
|
||||||
try {
|
try {
|
||||||
fis = new FileInputStream(sfile);
|
fis = new FileInputStream(sfile);
|
||||||
|
} catch (IOException ioe) {
|
||||||
|
// catch this here so we don't try do delete it below
|
||||||
|
addMessage(_("Cannot open \"{0}\"", sfile.getName()) + ": " + ioe.getMessage());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
MetaInfo info = new MetaInfo(fis);
|
MetaInfo info = new MetaInfo(fis);
|
||||||
fis.close();
|
try {
|
||||||
fis = null;
|
fis.close();
|
||||||
|
fis = null;
|
||||||
|
} catch (IOException e) {}
|
||||||
|
|
||||||
if (!TrackerClient.isValidAnnounce(info.getAnnounce())) {
|
if (!TrackerClient.isValidAnnounce(info.getAnnounce())) {
|
||||||
if (_util.shouldUseOpenTrackers() && _util.getOpenTrackers() != null) {
|
if (_util.shouldUseOpenTrackers() && _util.getOpenTrackers() != null) {
|
||||||
|
@ -420,13 +420,29 @@ public class Storage
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static final char[] ILLEGAL = new char[] {
|
||||||
|
'<', '>', ':', '"', '/', '\\', '|', '?', '*',
|
||||||
|
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
|
||||||
|
16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31 };
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes 'suspicious' characters from the give file name.
|
* Removes 'suspicious' characters from the given file name.
|
||||||
|
* http://msdn.microsoft.com/en-us/library/aa365247%28VS.85%29.aspx
|
||||||
*/
|
*/
|
||||||
private static String filterName(String name)
|
private static String filterName(String name)
|
||||||
{
|
{
|
||||||
// XXX - Is this enough?
|
if (name.equals(".") || name.equals(" "))
|
||||||
return name.replace(File.separatorChar, '_');
|
return "_";
|
||||||
|
String rv = name;
|
||||||
|
if (rv.startsWith("."))
|
||||||
|
rv = '_' + rv.substring(1);
|
||||||
|
if (rv.endsWith(".") || rv.endsWith(" "))
|
||||||
|
rv = rv.substring(0, rv.length() - 1) + '_';
|
||||||
|
for (int i = 0; i < ILLEGAL.length; i++) {
|
||||||
|
if (rv.indexOf(ILLEGAL[i]) >= 0)
|
||||||
|
rv = rv.replace(ILLEGAL[i], '_');
|
||||||
|
}
|
||||||
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
private File createFileFromNames(File base, List names) throws IOException
|
private File createFileFromNames(File base, List names) throws IOException
|
||||||
@ -577,6 +593,9 @@ public class Storage
|
|||||||
if (rafs == null) return;
|
if (rafs == null) return;
|
||||||
for (int i = 0; i < rafs.length; i++)
|
for (int i = 0; i < rafs.length; i++)
|
||||||
{
|
{
|
||||||
|
// if we had an IOE in check(), the RAFlock may be null
|
||||||
|
if (RAFlock[i] == null)
|
||||||
|
continue;
|
||||||
try {
|
try {
|
||||||
synchronized(RAFlock[i]) {
|
synchronized(RAFlock[i]) {
|
||||||
closeRAF(i);
|
closeRAF(i);
|
||||||
|
@ -179,7 +179,7 @@ public class BEValue
|
|||||||
if (value instanceof byte[])
|
if (value instanceof byte[])
|
||||||
{
|
{
|
||||||
byte[] bs = (byte[])value;
|
byte[] bs = (byte[])value;
|
||||||
// XXX - Stupid heuristic...
|
// XXX - Stupid heuristic... and not UTF-8
|
||||||
if (bs.length <= 12)
|
if (bs.length <= 12)
|
||||||
valueString = new String(bs);
|
valueString = new String(bs);
|
||||||
else
|
else
|
||||||
|
Reference in New Issue
Block a user