mirror of
https://github.com/claunia/plist-cil.git
synced 2025-12-16 19:14:26 +00:00
Fix issue when handling 0-length streams.
This commit is contained in:
20
plist-cil.test/PropertyListParserTests.cs
Normal file
20
plist-cil.test/PropertyListParserTests.cs
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
using Claunia.PropertyList;
|
||||||
|
using NUnit.Framework;
|
||||||
|
using System.IO;
|
||||||
|
|
||||||
|
namespace plistcil.test
|
||||||
|
{
|
||||||
|
[TestFixture]
|
||||||
|
public class PropertyListParserTests
|
||||||
|
{
|
||||||
|
[Test]
|
||||||
|
[ExpectedException(typeof(PropertyListFormatException))]
|
||||||
|
public static void ParseEmptyStreamTest()
|
||||||
|
{
|
||||||
|
using (MemoryStream stream = new MemoryStream())
|
||||||
|
{
|
||||||
|
PropertyListParser.Parse(stream);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -39,6 +39,7 @@
|
|||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
<Compile Include="ParseTest.cs" />
|
<Compile Include="ParseTest.cs" />
|
||||||
<Compile Include="IssueTest.cs" />
|
<Compile Include="IssueTest.cs" />
|
||||||
|
<Compile Include="PropertyListParserTests.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
@@ -81,7 +81,7 @@ namespace Claunia.PropertyList
|
|||||||
//Skip Unicode byte order mark (BOM)
|
//Skip Unicode byte order mark (BOM)
|
||||||
offset += 3;
|
offset += 3;
|
||||||
}
|
}
|
||||||
while (offset < bytes.Length && bytes[offset] == ' ' || bytes[offset] == '\t' || bytes[offset] == '\r' || bytes[offset] == '\n' || bytes[offset] == '\f')
|
while (offset < bytes.Length && (bytes[offset] == ' ' || bytes[offset] == '\t' || bytes[offset] == '\r' || bytes[offset] == '\n' || bytes[offset] == '\f'))
|
||||||
{
|
{
|
||||||
offset++;
|
offset++;
|
||||||
}
|
}
|
||||||
@@ -129,16 +129,11 @@ namespace Claunia.PropertyList
|
|||||||
/// <param name="fs">The Stream pointing to the data that should be stored in the array.</param>
|
/// <param name="fs">The Stream pointing to the data that should be stored in the array.</param>
|
||||||
internal static byte[] ReadAll(Stream fs)
|
internal static byte[] ReadAll(Stream fs)
|
||||||
{
|
{
|
||||||
MemoryStream outputStream = new MemoryStream();
|
using (MemoryStream outputStream = new MemoryStream())
|
||||||
byte[] buf = new byte[512];
|
|
||||||
int read = 512;
|
|
||||||
while (read == 512)
|
|
||||||
{
|
{
|
||||||
read = fs.Read(buf, 0, 512);
|
fs.CopyTo(outputStream);
|
||||||
if (read != -1)
|
return outputStream.ToArray();
|
||||||
outputStream.Write(buf, 0, read);
|
|
||||||
}
|
}
|
||||||
return outputStream.ToArray();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
Reference in New Issue
Block a user