ImagingDataCommons / libdicom

C library for reading DICOM files
https://libdicom.readthedocs.io
MIT License
16 stars 8 forks source link

Bug - Floating point exception #83

Closed voidz0r closed 7 months ago

voidz0r commented 7 months ago

Introduction

The issue comes whenever a zero value is passed to one of the width,height parameter of the tile.

https://github.com/ImagingDataCommons/libdicom/blob/345eda55428b04182233615afeaa10ce10a0cbe1/src/dicom-file.c#L335-L363

Debugging it with gdb shows the following: 02_floating_point_exception

With the value of width and frame_width set to 0. 03_breakpoint

This is possible by crafting a DCM file with the following byte sequences: 04_hex

Impact

The application just crashes with no further consequence. This issue does not seem to affect related products such as openslide.

Solution

The solution would be to check if the provided values are different from zero, and returns an error whenever this happens.

Attached the payload:

floatpe.zip

jcupitt commented 7 months ago

I fixed this with https://github.com/ImagingDataCommons/libdicom/commit/17d7e756a4f57a22caa7f4d54b34adcef957cf68 and credited you in the changelog (I hope that's OK).

Thank you for the very clear bug report!

jcupitt commented 7 months ago

I did a little quick grepping and I couldn't see any similar /0 issues.

voidz0r commented 7 months ago

Looks good to me. Thanks for the mention in the changelog :)