Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exception "'NoneType' object has no attribute 'decode'" when character set is empty. #1038

Closed
micjuel opened this issue Jan 21, 2020 · 6 comments · Fixed by #1039
Closed
Labels

Comments

@micjuel
Copy link

micjuel commented Jan 21, 2020

Describe the bug
If Transfer Syntax UID(0002,0010) is "1.2.840.10008.1.2" (LEI) and Character Set(0008,0005) is empty (that is assuming "ISO-IR 6"), there is an exception ("'NoneType' object has no attribute 'decode'").

Expected behavior
No exception. Defaulting to ISO-IR 6.

Steps To Reproduce
Use the attached dcm file and run :

ds = pydicom.dcmread("empty_charset_LEI.dcm") 

Traceback:

Exception has occurred: AttributeError
'NoneType' object has no attribute 'decode'
  File "C:\Program Files\Python38\Lib\site-packages\pydicom\values.py", line 370, in convert_string
    byte_string = byte_string.decode(default_encoding)
  File "C:\Program Files\Python38\Lib\site-packages\pydicom\filereader.py", line 208, in data_element_generator
    encoding = convert_string(value, is_little_endian)
  File "C:\Program Files\Python38\Lib\site-packages\pydicom\filereader.py", line 378, in read_dataset
    raw_data_element = next(de_gen)
  File "C:\Program Files\Python38\Lib\site-packages\pydicom\filereader.py", line 751, in read_partial
    dataset = read_dataset(fileobj, is_implicit_VR, is_little_endian,
  File "C:\Program Files\Python38\Lib\site-packages\pydicom\filereader.py", line 878, in dcmread
    dataset = read_partial(fp, stop_when, defer_size=defer_size,
  File "D:\test_dicom.py", line 57, in <module>
    ds = pydicom.dcmread(filename)

Your environment
Windows-10-10.0.18362-SP0
Python 3.8.1 (tags/v3.8.1:1b293b6, Dec 18 2019, 23:11:46) [MSC v.1916 64 bit (AMD64)]
pydicom 1.4.1

empty_charset_LEI.zip

@micjuel micjuel changed the title Got exception "'NoneType' object has no attribute 'decode'" Exception "'NoneType' object has no attribute 'decode'" when character set is empty. Jan 21, 2020
@mrbean-bremen
Copy link
Member

This is strictly speaking invalid DICOM (Specific Character Set is type 1C and cannot be empty), and I have never seen that so far. Anyway, it makes sense to handle this case as a missing tag (e.g. ISO-IR 6).

@mrbean-bremen
Copy link
Member

And given that empty values can always happen (despite the standard) we should always handle it without crashing, so this a bug anyway IMO.

@micjuel
Copy link
Author

micjuel commented Jan 21, 2020

After verification, you are right, it is strictly speaking invalid DICOM.

@mrbean-bremen
Copy link
Member

Can we use your example dataset for testing? It is a nice little dataset.

@micjuel
Copy link
Author

micjuel commented Jan 21, 2020

Yes for sure.

mrbean-bremen added a commit to mrbean-bremen/pydicom that referenced this issue Jan 21, 2020
darcymason pushed a commit that referenced this issue Jan 21, 2020
* Correctly handle reading empty Specific Character Set

- fixes #1038

* Removed unneeded check for Specific Character Set

- the check was for a tag with undefined length, which cannot be
  Specific Character Set
darcymason pushed a commit that referenced this issue Feb 20, 2020
* Correctly handle reading empty Specific Character Set

- fixes #1038

* Removed unneeded check for Specific Character Set

- the check was for a tag with undefined length, which cannot be
  Specific Character Set
@scaramallion
Copy link
Member

Should be fixed with v1.4.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants