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

Bug - Floating point exception #83

Closed
voidz0r opened this issue Feb 16, 2024 · 3 comments
Closed

Bug - Floating point exception #83

voidz0r opened this issue Feb 16, 2024 · 3 comments

Comments

@voidz0r
Copy link

voidz0r commented Feb 16, 2024

Introduction

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

libdicom/src/dicom-file.c

Lines 335 to 363 in 345eda5

static bool get_tiles(DcmError **error,
const DcmDataSet *metadata,
uint32_t *tiles_across,
uint32_t *tiles_down)
{
int64_t width;
int64_t height;
uint32_t frame_width;
uint32_t frame_height;
if (!get_frame_size(error, metadata, &frame_width, &frame_height)) {
return false;
}
// TotalPixelMatrixColumns is optional and defaults to Columns, ie. one
// frame across
width = frame_width;
(void) get_tag_int(NULL, metadata, "TotalPixelMatrixColumns", &width);
// TotalPixelMatrixColumns is optional and defaults to Columns, ie. one
// frame across
height = frame_width;
(void) get_tag_int(NULL, metadata, "TotalPixelMatrixRows", &height);
*tiles_across = (uint32_t) width / frame_width + !!(width % frame_width);
*tiles_down = (uint32_t) height / frame_height + !!(height % frame_height);
return true;
}

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 added a commit that referenced this issue Feb 16, 2024
Thanks voidz0r

See #83
@jcupitt
Copy link
Collaborator

jcupitt commented Feb 16, 2024

I fixed this with 17d7e75 and credited you in the changelog (I hope that's OK).

Thank you for the very clear bug report!

@jcupitt jcupitt closed this as completed Feb 16, 2024
@jcupitt
Copy link
Collaborator

jcupitt commented Feb 16, 2024

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

@voidz0r
Copy link
Author

voidz0r commented Feb 16, 2024

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

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

No branches or pull requests

2 participants