Skip to content

Commit dcee63a

Browse files
committed
Merge pull request #93 from matthew-brett/csa-itemlen0-fix
BF+TST - Allow 0 len items in CSA hdr if VM != 0
2 parents a3e3240 + 50d925a commit dcee63a

File tree

3 files changed

+17
-7
lines changed

3 files changed

+17
-7
lines changed

nibabel/nicom/csareader.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -137,13 +137,12 @@ def read(csa_str):
137137
continue
138138
item = nt_str(up_str.read(item_len))
139139
if converter:
140-
if vm == 0:
141-
# we may have fewer real items than are given in
142-
# n_items, but we don't know how many - assume that
143-
# we've reached the end when we hit an empty item
144-
if item_len == 0:
145-
n_values = item_no
146-
continue
140+
# we may have fewer real items than are given in
141+
# n_items, but we don't know how many - assume that
142+
# we've reached the end when we hit an empty item
143+
if item_len == 0:
144+
n_values = item_no
145+
continue
147146
item = converter(item)
148147
items.append(item)
149148
# go to 4 byte boundary
9.34 KB
Binary file not shown.

nibabel/nicom/tests/test_csareader.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
""" Testing Siemens CSA header reader
22
"""
33
from os.path import join as pjoin
4+
import gzip
45

56
import numpy as np
67

@@ -17,6 +18,7 @@
1718

1819
CSA2_B0 = open(pjoin(IO_DATA_PATH, 'csa2_b0.bin'), 'rb').read()
1920
CSA2_B1000 = open(pjoin(IO_DATA_PATH, 'csa2_b1000.bin'), 'rb').read()
21+
CSA2_0len = gzip.open(pjoin(IO_DATA_PATH, 'csa2_zero_len.bin.gz'), 'rb').read()
2022

2123

2224
@dicom_test
@@ -44,6 +46,15 @@ def test_csas0():
4446
assert_equal(b_value['items'], [1000])
4547

4648

49+
def test_csa_len0():
50+
# We did get a failure for item with item_len of 0 - gh issue #92
51+
csa_info = csa.read(CSA2_0len)
52+
assert_equal(csa_info['type'], 2)
53+
assert_equal(csa_info['n_tags'], 44)
54+
tags = csa_info['tags']
55+
assert_equal(len(tags), 44)
56+
57+
4758
def test_csa_params():
4859
for csa_str in (CSA2_B0, CSA2_B1000):
4960
csa_info = csa.read(csa_str)

0 commit comments

Comments
 (0)