Check there are no more than two consecutive nulls (UTF-16 can

have one null).
This commit is contained in:
2017-08-07 16:07:27 +01:00
parent 5d8fabf3d0
commit dc19f68e7a
4 changed files with 60 additions and 8 deletions

View File

@@ -248,9 +248,22 @@ namespace DiscImageChef.ImagePlugins
imageFilter.GetDataForkStream().Read(testArray, 0, 512);
imageFilter.GetDataForkStream().Seek(0, SeekOrigin.Begin);
// Check for unexpected control characters that shouldn't be present in a text file and can crash this plugin
foreach(byte b in testArray)
bool twoConsecutiveNulls = false;
for(int i = 0; i < 512; i++)
{
if(b < 0x20 && b != 0x0A && b != 0x0D && b != 0x00)
if(i >= imageFilter.GetDataForkStream().Length)
break;
if(testArray[i] == 0)
{
if(twoConsecutiveNulls)
return false;
twoConsecutiveNulls = true;
}
else
twoConsecutiveNulls = false;
if(testArray[i] < 0x20 && testArray[i] != 0x0A && testArray[i] != 0x0D && testArray[i] != 0x00)
return false;
}

View File

@@ -320,9 +320,22 @@ namespace DiscImageChef.ImagePlugins
imageFilter.GetDataForkStream().Read(testArray, 0, 512);
imageFilter.GetDataForkStream().Seek(0, SeekOrigin.Begin);
// Check for unexpected control characters that shouldn't be present in a text file and can crash this plugin
foreach(byte b in testArray)
bool twoConsecutiveNulls = false;
for(int i = 0; i < 512; i++)
{
if(b < 0x20 && b != 0x0A && b != 0x0D && b != 0x00)
if(i >= imageFilter.GetDataForkStream().Length)
break;
if(testArray[i] == 0)
{
if(twoConsecutiveNulls)
return false;
twoConsecutiveNulls = true;
}
else
twoConsecutiveNulls = false;
if(testArray[i] < 0x20 && testArray[i] != 0x0A && testArray[i] != 0x0D && testArray[i] != 0x00)
return false;
}

View File

@@ -127,9 +127,22 @@ namespace DiscImageChef.DiscImages
imageFilter.GetDataForkStream().Read(testArray, 0, 512);
imageFilter.GetDataForkStream().Seek(0, SeekOrigin.Begin);
// Check for unexpected control characters that shouldn't be present in a text file and can crash this plugin
foreach(byte b in testArray)
bool twoConsecutiveNulls = false;
for(int i = 0; i < 512; i++)
{
if(b < 0x20 && b != 0x0A && b != 0x0D && b != 0x00)
if(i >= imageFilter.GetDataForkStream().Length)
break;
if(testArray[i] == 0)
{
if(twoConsecutiveNulls)
return false;
twoConsecutiveNulls = true;
}
else
twoConsecutiveNulls = false;
if(testArray[i] < 0x20 && testArray[i] != 0x0A && testArray[i] != 0x0D && testArray[i] != 0x00)
return false;
}

View File

@@ -138,9 +138,22 @@ namespace DiscImageChef.ImagePlugins
imageFilter.GetDataForkStream().Read(testArray, 0, 512);
imageFilter.GetDataForkStream().Seek(0, SeekOrigin.Begin);
// Check for unexpected control characters that shouldn't be present in a text file and can crash this plugin
foreach(byte b in testArray)
bool twoConsecutiveNulls = false;
for(int i = 0; i < 512; i++)
{
if(b < 0x20 && b != 0x0A && b != 0x0D && b != 0x00)
if(i >= imageFilter.GetDataForkStream().Length)
break;
if(testArray[i] == 0)
{
if(twoConsecutiveNulls)
return false;
twoConsecutiveNulls = true;
}
else
twoConsecutiveNulls = false;
if(testArray[i] < 0x20 && testArray[i] != 0x0A && testArray[i] != 0x0D && testArray[i] != 0x00)
return false;
}
gdiStream = new StreamReader(imageFilter.GetDataForkStream());