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

Division by zero in GenerateDifferentialNoise() in MagickCore/gem.c #3077

Closed
hifoolno opened this issue Jan 6, 2021 · 8 comments
Closed

Comments

@hifoolno
Copy link
Contributor

hifoolno commented Jan 6, 2021

When attenuate was set to zero, SigmaPoisson would be zero too. So a crafted file may trigger undefined behavior in the form of division by zero. Maybe there need a check on SigmaPoisson before line 1590?

ImageMagick/MagickCore/gem.c

Lines 1576 to 1592 in 0d20727

case PoissonNoise:
{
double
poisson;
ssize_t
i;
poisson=exp(-SigmaPoisson*QuantumScale*pixel);
for (i=0; alpha > poisson; i++)
{
beta=GetPseudoRandomValue(random_info);
alpha*=beta;
}
noise=(double) (QuantumRange*i/SigmaPoisson);
break;
}

@urban-warrior
Copy link
Member

Thanks for the problem report. We can reproduce it and will have a patch to fix it in the GIT master branch @ https://github.com/ImageMagick/ImageMagick later today. The patch will be available in the beta releases of ImageMagick @ https://www.imagemagick.org/download/beta/ by sometime tomorrow.

urban-warrior pushed a commit to ImageMagick/ImageMagick6 that referenced this issue Jan 6, 2021
@carnil
Copy link

carnil commented Feb 5, 2021

This issue was assigned CVE-2021-20176

@StayPirate
Copy link

Hi @urban-warrior, do you think the following lines are relevant for this vulnerability?

ImageMagick:

noise=(QuantumRange*i/SigmaPoisson);

ImageMagick6:
https://github.com/ImageMagick/ImageMagick6/blob/210e4177f70a2ab4b5138c1453e50c9384d1626e/magick/accelerate-kernels-private.h#L706

@urban-warrior
Copy link
Member

Yes. We'll add a patch.

urban-warrior pushed a commit to ImageMagick/ImageMagick6 that referenced this issue Feb 5, 2021
@StayPirate
Copy link

can you please explain me why there are two different commits addressing the same line of code?? 4103225 and fbd9a96

@urban-warrior
Copy link
Member

We maintain two different releases of ImageMagick. IMv6 & IMv7.

@StayPirate
Copy link

Yes, but these are both for IMv7. IMv6 is in a different repo, am I wrong?

@StayPirate
Copy link

I got it, you merged 4103225 in the a0d7cbc, resulting in an empty merge. That's because the same changes were applied by fbd9a96 the 7th of Jan.

woodsts pushed a commit to woodsts/buildroot that referenced this issue Feb 26, 2021
Fixes the following security issue:

CVE-2021-20176: A divide-by-zero flaw was found in ImageMagick 6.9.11-57 and
7.0.10-57 in gem.c.  This flaw allows an attacker who submits a crafted file
that is processed by ImageMagick to trigger undefined behavior through a
division by zero.  The highest threat from this vulnerability is to system
availability.

For more details, see the bugtracker:
ImageMagick/ImageMagick#3077

- bump version to 7.0.10-62
- update license file hash (copyright year update)

Signed-off-by: Peter Seiderer <ps.report@gmx.net>
[Peter: mention security fix]
Signed-off-by: Peter Korsgaard <peter@korsgaard.com>
buildroot-auto-update pushed a commit to buildroot/buildroot that referenced this issue Mar 5, 2021
Fixes the following security issue:

CVE-2021-20176: A divide-by-zero flaw was found in ImageMagick 6.9.11-57 and
7.0.10-57 in gem.c.  This flaw allows an attacker who submits a crafted file
that is processed by ImageMagick to trigger undefined behavior through a
division by zero.  The highest threat from this vulnerability is to system
availability.

For more details, see the bugtracker:
ImageMagick/ImageMagick#3077

- bump version to 7.0.10-62
- update license file hash (copyright year update)

Signed-off-by: Peter Seiderer <ps.report@gmx.net>
[Peter: mention security fix]
Signed-off-by: Peter Korsgaard <peter@korsgaard.com>
(cherry picked from commit a11b6be)
Signed-off-by: Peter Korsgaard <peter@korsgaard.com>
buildroot-auto-update pushed a commit to buildroot/buildroot that referenced this issue Mar 5, 2021
Fixes the following security issue:

CVE-2021-20176: A divide-by-zero flaw was found in ImageMagick 6.9.11-57 and
7.0.10-57 in gem.c.  This flaw allows an attacker who submits a crafted file
that is processed by ImageMagick to trigger undefined behavior through a
division by zero.  The highest threat from this vulnerability is to system
availability.

For more details, see the bugtracker:
ImageMagick/ImageMagick#3077

- bump version to 7.0.10-62
- update license file hash (copyright year update)

Signed-off-by: Peter Seiderer <ps.report@gmx.net>
[Peter: mention security fix]
Signed-off-by: Peter Korsgaard <peter@korsgaard.com>
(cherry picked from commit a11b6be)
Signed-off-by: Peter Korsgaard <peter@korsgaard.com>
@dlemstra dlemstra closed this as completed Jul 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

5 participants