From 2fdff8e040cd4401498d89f3c3d1f89cffd118b0 Mon Sep 17 00:00:00 2001
From: Cristy <urban-warrior@imagemagick.org>
Date: Fri, 4 Oct 2019 19:00:10 -0400
Subject: [PATCH] https://github.com/ImageMagick/ImageMagick/issues/1715

---
 coders/png.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/coders/png.c b/coders/png.c
index af50b863d..410741059 100644
--- a/coders/png.c
+++ b/coders/png.c
@@ -8790,7 +8790,7 @@ static MagickBooleanType WriteOnePNGImage(MngInfo *mng_info,
          (void) LogMagickEvent(CoderEvent,GetMagickModule(),
              "        i    (red,green,blue,opacity)");
 
-         for (i=0; i < 256; i++)
+         for (i=0; i < MagickMin(image->colors,256); i++)
          {
                (void) LogMagickEvent(CoderEvent,GetMagickModule(),
                    "        %d    (%d,%d,%d,%d)",
