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="ParseTest.cs" />
|
||||
<Compile Include="IssueTest.cs" />
|
||||
<Compile Include="PropertyListParserTests.cs" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||
<ItemGroup>
|
||||
|
||||
@@ -81,7 +81,7 @@ namespace Claunia.PropertyList
|
||||
//Skip Unicode byte order mark (BOM)
|
||||
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++;
|
||||
}
|
||||
@@ -129,17 +129,12 @@ namespace Claunia.PropertyList
|
||||
/// <param name="fs">The Stream pointing to the data that should be stored in the array.</param>
|
||||
internal static byte[] ReadAll(Stream fs)
|
||||
{
|
||||
MemoryStream outputStream = new MemoryStream();
|
||||
byte[] buf = new byte[512];
|
||||
int read = 512;
|
||||
while (read == 512)
|
||||
using (MemoryStream outputStream = new MemoryStream())
|
||||
{
|
||||
read = fs.Read(buf, 0, 512);
|
||||
if (read != -1)
|
||||
outputStream.Write(buf, 0, read);
|
||||
}
|
||||
fs.CopyTo(outputStream);
|
||||
return outputStream.ToArray();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parses a property list from a file.
|
||||
|
||||
Reference in New Issue
Block a user