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

fix issue with odd number of pixel bytes #233

Merged
merged 12 commits into from
Jul 5, 2022

Conversation

jabillings
Copy link
Contributor

There have been several issues that mention EOF errors. (e.g. #62) This PR fixes an error that manifested itself with an EOF error, so it may address those.

The problem occurs when there is an odd number of bytes in the pixel data, and even though the value length is even, the parser doesn't count the last padding byte.

Regarding the implementation, it might be more robust to skip ahead the difference between vl and bytesRead in readNativeFrames, but my understanding of this library and the DICOM standard is that the difference will always be 0 or 1.

Copy link
Owner

@suyashkumar suyashkumar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR! Overall looking good, just had a couple comments for you to consider as well.

And indeed historically there have been EOF errors that result from various edge cases that we've been fixing example by example over time--like this one! So appreciate it!

read.go Outdated Show resolved Hide resolved
read_test.go Outdated
@@ -392,6 +392,135 @@ func TestReadNativeFrames(t *testing.T) {
}
}

func TestReadNativeFrames_BytePixels(t *testing.T) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question, in order to test the padded byte case, can we just better parametrize the above test? Esp because the test body seems like it's the same.

One thought could be to introduce a dataBytes parameter into the above test case. If len(data) ==0 in the test case, then we pass dataBytes to binary.Write instead.

What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I cleaned it up like you suggested, see what you think

read_test.go Outdated
@@ -392,6 +392,135 @@ func TestReadNativeFrames(t *testing.T) {
}
}

func TestReadNativeFrames_BytePixels(t *testing.T) {
cases := []struct {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add a test case to test for the condition where vl%2 != 0 and assert that we get an expectedError we want? We would probably also want to have some kind of sentinel error we return to make checking this easy (e.g. kinda like ErrorUnsupportedBitsAllocated

jabillings and others added 2 commits January 31, 2022 18:31
Co-authored-by: Suyash Kumar <suyashkumar2003@gmail.com>
Copy link
Owner

@suyashkumar suyashkumar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the changes! Overall looking good to me, just had a few more comments and adjustments for you to consider.

read.go Outdated Show resolved Hide resolved
read.go Outdated Show resolved Hide resolved
read_test.go Outdated Show resolved Hide resolved
read_test.go Outdated Show resolved Hide resolved
read_test.go Outdated Show resolved Hide resolved
read_test.go Outdated Show resolved Hide resolved
read_test.go Outdated Show resolved Hide resolved
read_test.go Outdated Show resolved Hide resolved
jabillings and others added 8 commits February 11, 2022 13:16
Co-authored-by: Suyash Kumar <suyashkumar2003@gmail.com>
Co-authored-by: Suyash Kumar <suyashkumar2003@gmail.com>
Co-authored-by: Suyash Kumar <suyashkumar2003@gmail.com>
Co-authored-by: Suyash Kumar <suyashkumar2003@gmail.com>
Co-authored-by: Suyash Kumar <suyashkumar2003@gmail.com>
Co-authored-by: Suyash Kumar <suyashkumar2003@gmail.com>
Co-authored-by: Suyash Kumar <suyashkumar2003@gmail.com>
Copy link
Owner

@suyashkumar suyashkumar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, just two minor nits left and this should be ready to merge! Thanks for the contribution!

read.go Outdated Show resolved Hide resolved
read_test.go Outdated Show resolved Hide resolved
@suyashkumar suyashkumar merged commit 836cc53 into suyashkumar:main Jul 5, 2022
@suyashkumar suyashkumar mentioned this pull request May 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants