pydicom / dicom-validator

Simple DICOM validator based on DocBook DICOM specs
MIT License
24 stars 11 forks source link

string index out of range error when using the Windows executable #119

Closed chielmi closed 2 months ago

chielmi commented 2 months ago

Let me start with saying thanks for creating the packaged Windows executables version 0.6.1 for dump_dcm_info.exe and validate_iods.exe!

Unfortunately they don't work for me. When running these I get an unhandled exception when docbook files are created for the first run. I can see the files being downloaded to the docbook directory, so it doesn't seem to be a permission issue:

.\validate_iods.exe -src .\docbook .\testfile.dcm
Creating JSON excerpts from docbook files...
Traceback (most recent call last):
  File "dicom_validator\validate_iods.py", line 80, in <module>
  File "dicom_validator\validate_iods.py", line 71, in main
  File "dicom_validator\spec_reader\edition_reader.py", line 244, in get_revision
  File "dicom_validator\spec_reader\edition_reader.py", line 200, in create_json_files
  File "dicom_validator\spec_reader\part3_reader.py", line 85, in iod_descriptions
  File "dicom_validator\spec_reader\part3_reader.py", line 88, in <dictcomp>
  File "dicom_validator\spec_reader\part3_reader.py", line 70, in iod_description
  File "dicom_validator\spec_reader\part3_reader.py", line 176, in _parse_iod_node
  File "dicom_validator\spec_reader\part3_reader.py", line 376, in _get_iod_modules
  File "dicom_validator\spec_reader\part3_reader.py", line 357, in _collect_modules
  File "dicom_validator\spec_reader\part3_reader.py", line 108, in module_description
  File "dicom_validator\spec_reader\part3_reader.py", line 204, in _parse_module_description
  File "dicom_validator\spec_reader\part3_reader.py", line 239, in _handle_included_attributes
  File "dicom_validator\spec_reader\part3_reader.py", line 200, in _parse_module_description
  File "dicom_validator\spec_reader\part3_reader.py", line 269, in _handle_regular_attribute
  File "dicom_validator\spec_reader\condition_parser.py", line 109, in parse
  File "dicom_validator\spec_reader\condition_parser.py", line 392, in _parse_tag_expressions
  File "dicom_validator\spec_reader\condition_parser.py", line 141, in _parse_tag_expression
  File "dicom_validator\spec_reader\condition_parser.py", line 303, in _parse_tag_values
  File "dicom_validator\spec_reader\condition_parser.py", line 353, in _get_const_value
IndexError: string index out of range
[17072] Failed to execute script 'validate_iods' due to unhandled exception!

Any suggestion on what I'm doing wrong here?

mrbean-bremen commented 2 months ago

Thanks for the report! This sounds more like a bug in the condition parser itself. I actually can see that there is a check missing. It would be helpful if you could provide the test file (or an anonymized version that still shows this error) to understand when this error occurs.

chielmi commented 2 months ago

Thanks for the quick reply! I get this error for any DICOM file, even for the ones that I know don't contain any issues. Also I have the exact same error when I run validate_iods.exe in an Ubuntu VM.

Perhaps it's an issue in the latest version?

mrbean-bremen commented 2 months ago

Perhaps it's an issue in the latest version?

Could be - would be a bit awkward if no test did catch this... Can you please check with the previous version 0.6.0 (it also has the executable)? I will certainly have a look later today.

chielmi commented 2 months ago

You are spot on! I can confirm that 0.6.0 works fine, I only have the issue with 0.6.1!

mrbean-bremen commented 2 months ago

Right - I just tried it locally, and it is indeed a regression in 0.6.1. Sorry for that... You can use version 0.6.0 until I fix that.

chielmi commented 2 months ago

All clear, indeed I'll use the prior version for now. Thanks again for the fast confirmation!

mrbean-bremen commented 2 months ago

A new patch release with a fix is out.

mrbean-bremen commented 2 months ago

For my own reference: this was not caught because the tests had been run with the 2023c DICOM standard, while the problem only occurs since 2024a. In a few conditions, a link had been introduced into the condition text instead of the previous text, and as the link is removed during processing, the resulting (incomplete) sentence led to the error due to a change in parsing in 0.6.0. We shall always use the latest standard for testing...