Skip to content

Commit

Permalink
Merge pull request #79 from kulbachinskii/master
Browse files Browse the repository at this point in the history
Avoid infinite while-loop
  • Loading branch information
rexcardan authored Sep 27, 2020
2 parents 9a976e5 + aa91fc2 commit 8f4144d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
10 changes: 5 additions & 5 deletions EvilDICOM/EvilDICOM/Core/IO/Reading/SequenceItemReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,13 @@ public static void SkipItemLittleEndian(DICOMBinaryReader dr, TransferSyntax syn
else
{
if (syntax == TransferSyntax.EXPLICIT_VR_LITTLE_ENDIAN)
while (!IsEndOfSequenceItemLittleEndian(dr))
while (!IsEndOfSequenceItemLittleEndian(dr) && dr.StreamLength != dr.StreamPosition)
{
dr.StreamPosition -= 8;
DICOMElementReader.SkipElementExplicitLittleEndian(dr);
}
else
while (!IsEndOfSequenceItemLittleEndian(dr))
while (!IsEndOfSequenceItemLittleEndian(dr) && dr.StreamLength != dr.StreamPosition)
{
dr.StreamPosition -= 8;
DICOMElementReader.SkipElementImplicitLittleEndian(dr);
Expand All @@ -72,7 +72,7 @@ public static void SkipItemBigEndian(DICOMBinaryReader dr)
if (length != -1)
dr.Skip(length);
else
while (!IsEndOfSequenceItemBigEndian(dr))
while (!IsEndOfSequenceItemBigEndian(dr) && dr.StreamLength != dr.StreamPosition)
{
dr.StreamPosition -= 8;
DICOMElementReader.SkipElementExplicitBigEndian(dr);
Expand All @@ -94,7 +94,7 @@ private static bool IsEndOfSequenceItemBigEndian(DICOMBinaryReader dr)
private static DICOMObject ReadIndefiniteBigEndian(DICOMBinaryReader dr, TransferSyntax syntax, StringEncoding enc)
{
var elements = new List<IDICOMElement>();
while (!IsEndOfSequenceItemLittleEndian(dr))
while (!IsEndOfSequenceItemLittleEndian(dr) && dr.StreamLength != dr.StreamPosition)
{
dr.StreamPosition -= 8;
elements.Add(DICOMElementReader.ReadElementExplicitBigEndian(dr, enc));
Expand All @@ -105,7 +105,7 @@ private static DICOMObject ReadIndefiniteBigEndian(DICOMBinaryReader dr, Transfe
private static DICOMObject ReadIndefiniteLittleEndian(DICOMBinaryReader dr, TransferSyntax syntax, StringEncoding enc)
{
var elements = new List<IDICOMElement>();
while (!IsEndOfSequenceItemLittleEndian(dr))
while (!IsEndOfSequenceItemLittleEndian(dr) && dr.StreamLength != dr.StreamPosition)
{
dr.StreamPosition -= 8;
if (syntax == TransferSyntax.EXPLICIT_VR_LITTLE_ENDIAN)
Expand Down
4 changes: 2 additions & 2 deletions EvilDICOM/EvilDICOM/Core/IO/Reading/SequenceReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class SequenceReader
public static int ReadIndefiniteLengthLittleEndian(DICOMBinaryReader dr, TransferSyntax syntax)
{
var startingPos = dr.StreamPosition;
while (!IsEndOfSequenceLittleEndian(dr))
while (!IsEndOfSequenceLittleEndian(dr) && dr.StreamLength != dr.StreamPosition)
{
dr.StreamPosition -= 8;
SequenceItemReader.SkipItemLittleEndian(dr, syntax);
Expand All @@ -27,7 +27,7 @@ public static int ReadIndefiniteLengthLittleEndian(DICOMBinaryReader dr, Transfe
public static int ReadIndefiniteLengthBigEndian(DICOMBinaryReader dr)
{
var startingPos = dr.StreamPosition;
while (!IsEndOfSequenceBigEndian(dr))
while (!IsEndOfSequenceBigEndian(dr) && dr.StreamLength != dr.StreamPosition)
{
dr.StreamPosition -= 8;
SequenceItemReader.SkipItemBigEndian(dr);
Expand Down

0 comments on commit 8f4144d

Please sign in to comment.