Skip to content

Enumerating the result of BinaryLog.ReadRecords twice crashes with EndOfStreamException #878

@jjonescz

Description

@jjonescz

Steps to reproduce:

dotnet new console
dotnet build -bl # to create sample binlog
dotnet add package MSBuild.StructuredLogger --version 2.2.472

Replace Program.cs with:

using Microsoft.Build.Logging.StructuredLogger;

var records = BinaryLog.ReadRecords("msbuild.binlog");
records.ToList(); // ok
records.ToList(); // crashes
dotnet run

Observed output:

Unhandled exception. System.IO.EndOfStreamException: Unable to read beyond the end of the stream.
   at System.IO.BinaryReader.ReadByte()
   at Microsoft.Build.Logging.StructuredLogger.BuildEventArgsReader.ReadInt32() in C:\MSBuildStructuredLog\src\StructuredLogger\BinaryLogger\BuildEventArgsReader.cs:line 1935
   at Microsoft.Build.Logging.StructuredLogger.BuildEventArgsReader.PreprocessRecordsTillNextEvent(Func`2 isPreprocessRecord) in C:\MSBuildStructuredLog\src\StructuredLogger\BinaryLogger\BuildEventArgsReader.cs:line 355
   at Microsoft.Build.Logging.StructuredLogger.BuildEventArgsReader.Read() in C:\MSBuildStructuredLog\src\StructuredLogger\BinaryLogger\BuildEventArgsReader.cs:line 226
   at Microsoft.Build.Logging.StructuredLogger.BinLogReader.ReadRecordsFromDecompressedStream(BuildEventArgsReader reader, Boolean includeAuxiliaryRecords)+MoveNext() in C:\MSBuildStructuredLog\src\StructuredLogger\BinaryLogger\BinLogReader.cs:line 442        
   at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
   at Program.<Main>$(String[] args) in Program.cs:line 5

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions