Skip to content

Commit

Permalink
Updates to odd value length logging
Browse files Browse the repository at this point in the history
  • Loading branch information
karl-exini committed Oct 17, 2020
1 parent 74641a7 commit 90f6bc4
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
4 changes: 4 additions & 0 deletions src/main/scala/com/exini/dicom/streams/CollectFlow.scala
Expand Up @@ -164,9 +164,13 @@ object CollectFlow {
case item: ItemPart =>
maybeAdd(ItemElement(item.index, item.length, item.bigEndian))
Nil
case _: ItemDelimitationPartMarker =>
Nil
case itemDelimitation: ItemDelimitationPart =>
maybeAdd(ItemDelimitationElement(itemDelimitation.index, itemDelimitation.bigEndian))
Nil
case SequenceDelimitationPartMarker =>
Nil
case sequenceDelimitation: SequenceDelimitationPart =>
maybeAdd(SequenceDelimitationElement(sequenceDelimitation.bigEndian))
Nil
Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/com/exini/dicom/streams/DicomFlow.scala
Expand Up @@ -273,7 +273,7 @@ trait GuaranteedDelimitationEvents[Out] extends DicomFlow[Out] with InFragments[
}
}

def subtractAndEmit[A <: DicomPart](part: A, handle: A => List[Out], isDelimit: Boolean = false): List[Out] = {
def subtractAndEmit[A <: DicomPart](part: A, handle: A => List[Out]): List[Out] = {
partStack = subtractLength(part)
handle(part) ::: maybeDelimit()
}
Expand Down
12 changes: 6 additions & 6 deletions src/main/scala/com/exini/dicom/streams/ParseFlow.scala
Expand Up @@ -36,6 +36,10 @@ class ParseFlow private (chunkSize: Int) extends ByteStringParser[DicomPart] {

protected class DicomParsingLogic extends ParsingLogic with StageLogging {

private def warnIfOdd(tag: Int, vr: VR, valueLength: Long): Unit =
if (valueLength % 2 > 0 && valueLength != indeterminateLength && vr != null && vr != VR.SQ)
log.warning(s"Element ${tagToString(tag)} has odd length")

sealed trait HeaderState {
val bigEndian: Boolean
val explicitVR: Boolean
Expand Down Expand Up @@ -142,8 +146,7 @@ class ParseFlow private (chunkSize: Int) extends ByteStringParser[DicomPart] {

def parse(reader: ByteReader): ParseResult[DicomPart] = {
val (tag, vr, headerLength, valueLength) = readHeader(reader, state)
if (valueLength % 2 > 0)
log.warning(s"Element ${tagToString(tag)} has odd length")
warnIfOdd(tag, vr, valueLength)
if (groupNumber(tag) != 2) {
log.warning("Missing or wrong File Meta Information Group Length (0002,0000)")
ParseResult(None, toDatasetStep(ByteString(0, 0), state))
Expand Down Expand Up @@ -210,8 +213,7 @@ class ParseFlow private (chunkSize: Int) extends ByteStringParser[DicomPart] {
case class InDatasetHeader(state: DatasetHeaderState) extends DicomParseStep {
private def readDatasetHeader(reader: ByteReader, state: DatasetHeaderState): Option[DicomPart] = {
val (tag, vr, headerLength, valueLength) = readHeader(reader, state)
if (valueLength % 2 > 0)
log.warning(s"Element ${tagToString(tag)} has odd length")
warnIfOdd(tag, vr, valueLength)
if (vr != null) {
val bytes = reader.take(headerLength)
if (vr == VR.SQ || vr == VR.UN && valueLength == indeterminateLength)
Expand Down Expand Up @@ -275,8 +277,6 @@ class ParseFlow private (chunkSize: Int) extends ByteStringParser[DicomPart] {
case class InFragments(state: FragmentsState) extends DicomParseStep {
def parse(reader: ByteReader): ParseResult[DicomPart] = {
val (tag, _, headerLength, valueLength) = readHeader(reader, state)
if (valueLength % 2 > 0)
log.warning(s"Element ${tagToString(tag)} has odd length")
tag match {

case 0xfffee000 => // begin fragment
Expand Down

0 comments on commit 90f6bc4

Please sign in to comment.