Skip to content

Commit

Permalink
Fixed invalid array access on EXS_Unknown.
Browse files Browse the repository at this point in the history
Fixed invalid access to XferNames array for transfer syntax enum
EXS_Unknown (-1). This issue was introduced only recently with commit
9872714.

Thanks to GitHub user "percontation" for the report and suggested fix.
This closes GitHub pull request #107.
  • Loading branch information
jriesmeier committed Aug 1, 2024
1 parent 0228702 commit 84c57f8
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions dcmdata/libsrc/dcxfer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -853,8 +853,8 @@ DcmXfer::DcmXfer(E_TransferSyntax xfer)
{
/* casting the enum to an integer should be safe */
const int i = OFstatic_cast(int, xfer);
/* ... but you never know, so double-check this */
if ((i < DIM_OF_XferNames) && (XferNames[i].xfer == xfer))
/* ... but double-check this to avoid invalid array access, e.g. for EXS_Unknown */
if ((i >= 0) && (i < DIM_OF_XferNames) && (XferNames[i].xfer == xfer))
{
xferSyn = XferNames[i].xfer;
xferID = XferNames[i].xferID;
Expand Down Expand Up @@ -959,8 +959,8 @@ DcmXfer &DcmXfer::operator=(const E_TransferSyntax xfer)
{
/* casting the enum to an integer should be safe */
const int i = OFstatic_cast(int, xfer);
/* ... but you never know, so double-check this */
if ((i < DIM_OF_XferNames) && (XferNames[i].xfer == xfer))
/* ... but double-check this to avoid invalid array access, e.g. for EXS_Unknown */
if ((i >= 0) && (i < DIM_OF_XferNames) && (XferNames[i].xfer == xfer))
{
xferSyn = XferNames[i].xfer;
xferID = XferNames[i].xferID;
Expand Down

0 comments on commit 84c57f8

Please sign in to comment.