ããã«ã¡ã¯ãã¢ããªã±ã¼ã·ã§ã³åºç¤ãã¼ã ã®éæ¨(@a_o_k_i_n_g)ã§ãã
ä¸è¬ç㪠Web ã¢ããªã±ã¼ã·ã§ã³ãããã§ããããã«ããµã¤ãã¦ãºã®ã°ã«ã¼ãã¦ã§ã¢ã«ãç»åããµã ãã¤ã«ã§è¡¨ç¤ºããæ©è½ãããã¾ãããµã¤ãã¦ãºã§ã¯æ¥ã æ°ä¸ä»¶ããã以ä¸ã®ãµã ãã¤ã«ãçæãã¦ããããããã¯å ¨ã¦ ImageMagick ã«ãã£ã¦çæããã¦ãã¾ããã
ããã§å¾ãç¥è¦ã¯ãã¡ãã®è¨äºã§å
¬éããã¦ãã¾ãã
blog.cybozu.io
ãããç¾å¨ããµã¤ãã¦ãºãã ImageMagick ã¯æ¶ãå»ãã¾ããããã®çç±ã¨ãæã ãåã£ã代æ¿æ段ã«ã¤ãã¦ç´¹ä»ãã¾ãã
ImageMagick ãå¤ããçç±
è¨ãã¾ã§ããªã ImageMagick ã¯åªç§ãªãã¼ã«ã§ãç»åå¤æã«é¢ããä½ããã®ãµã¼ãã¹ããã¼ã«ãä½ãå ´åã«ã¯æ¡ç¨ã®ç¬¬ä¸åè£ã«ãªããã¨ã§ããããããããç»åãã©ã¼ãããã«å¯¾å¿ããåºåç»åãããç´°ãã«å¶å¾¡ã§ããè¨å¤§ãªãªãã·ã§ã³ãããããã§ãã
ãããä¸æ¹ã§ã ImageMagick ã«ã¯èå¼±æ§ã大éã«åå¨ãã¾ãã2017 å¹´ã«å ±åããã ImageMagick ã®èå¼±æ§ã¯ 236 件 ã§ããã大éã«ããä¸ã«ãªã¢ã¼ãã³ã¼ãå®è¡ç´ã®èå¼±æ§ããããå®å
¨æ§ã¨ãã観ç¹ã§ã¯ããªãå³ããè©ä¾¡ãããªããã°ãªãã¾ããããã¡ãã« ImageMagick ã®èå¼±æ§æ
å ±ãããããã®å¤ãã伺ããã¨æãã¾ãã
Imagemagick : Security Vulnerabilities
ãã¡ãããæã 㯠AppArmor ã«ããå³éãªã¢ã¯ã»ã¹å¶å¾¡ããµã ãã¤ã«ä½æå°ç¨ã®ç°å¢ã使ããªã©ã®çã¯æ½ãã¦ãã¾ãããããããã§ãããã ãå¤æ°ã®èå¼±æ§ãããã¨ãªãã¨ã ã¦ã¼ã¶ã¼ã«å®å¿å®å ¨ãªã¯ã©ã¦ããµã¼ãã¹ãæä¾ã§ãã¦ãããï¼ ã¨ããç¹ã§çåãããã¾ããã
ã¾ããèå¼±æ§å ±åãæ¥ããã³ã«ãµã¤ãã¦ãºã«å½±é¿ãç¡ãã調æ»ãã¦ããããã®ã³ã¹ããç¡è¦ã§ããªãã»ã©å¤§ãããªãã¾ãããèå¼±æ§å ±åãæ¥ãéã¯å¦å¿ç¡ãã«èª¿æ»ã«æéãåããã¾ãããæå³ããªãã¿ã¤ãã³ã°ã§ãã¼ã¸ã§ã³ã¢ãããè¿«ããããã¨ãããã¾ããã¹ã ã¼ãºãªéç¨ã®ããã«ã ImageMagick ãæ¡ç¨ãç¶ããã®ã¯å¾çã§ã¯ãªãã ããã¨ããæè¦ãåºã¦ãã¾ããã
æ¤è¨ãéããçµæãæã 㯠ImageMagick ãæ¨ã¦ã決æããã¾ããã
ImageMagick ã®ä»£ããã«
代æ¿ã¨ãã¦ä½¿ããããªãã¼ã«ãããã¤ãããã¾ãããããµã¤ãã¦ãºã®ãµã ãã¤ã«äºæ ã¯å°ã ä»æ§ãåã£ã¦ããé¨åããããèªä½ãããã¨ã«ãã¾ãããããã¦èª¿æ»ã®çµæãGo è¨èªã¨ imaging ããã±ã¼ã¸ãè¯ãããã¨ãããã¨ã§ãããç¨ãã¦å®è£ ãããã¨ã«ãã¾ããã
çµè«ããè¨ãã°ãImageMagick ã«ä¾åããªããµã ãã¤ã«ä½æãã¼ã«ãå®è£ ãã移è¡ãçµãã¦ãã¾ããããã¤ãå¤æããç¹ã«ã¤ãã¦è¨ãã¾ãã
PNG ã®å¤æç»åãå ãã«æããªãã±ã¼ã¹ããã
Go çãµã ãã¤ã«çæãã¼ã«ã¨ ImageMagick ã§ã¯ãPNG ãå¤æããéã« Go çã®æ¹ããããã«è²ãæããªãã±ã¼ã¹ããããã¨ãå¤æãã¾ããã
Wikipedia ã® PNG ã®ãã¼ã¸ ã«ãã PNG ç»åãä¾ã«åã£ã¦èª¬æãã¾ããä¸æç®ã ImageMagick ã§å¤æããç»åãäºæç®ã Go çãµã ãã¤ã«çæãã¼ã«ã§å¤æããç»åã§ãã
ã»ã»ã»ã¨ããããã§ãèç¼ã§ã¯ãããã¾ããããImageMagick ã® compare ã³ãã³ãã§ç»åã®å·®åãåºåããã¨å·®åãæµ®ãã³ä¸ããã¾ãã
ç¨ã«èç¼ã§ãããç¨åº¦ã®å·®ãåºãç»åãããã«ã¯ããã¾ãããå®ç¨ã§ã¯åé¡ç¡ãã¨å¤æãã¾ããã
å¤æã§ããªãç»åããã
ImageMagick ã§å¤æåºæ¥ã¦ã Go çãµã ãã¤ã«çæãã¼ã«ã§ã¯å¤æåºæ¥ãªãç»åãããã¾ãã
ã¾ããGo çã§ã¯ BMP ã®ä¸é¨ã¯å¤æåºæ¥ã¾ãããBMP ã«ã¯ããã¤ã種é¡ãããããã®ç¨®é¡ã表ãå¤ã¯ Bitmap Information Header
ã¨ãããããé¨åã§æå®ããã¾ããããã§æå®ãããå¤ã¨ç¨®é¡ã¯ä¸è¨ã®éãã§ãã
å¤ | æå³ |
---|---|
40 | Windows V3 |
108 | Windows V4 |
124 | Windows V5 |
12 | OS/2 V1 |
64 | OS/2 V2 |
ããã Go ã® image ããã±ã¼ã¸ã®å½è©²é¨åãè¦ã㨠40 ã¨ããå¤ãæ¥ããã¨ãåæã¨ãã¦ãããWindows V3
以å¤ã® BMP ã®ãã¼ã¸ã§ã³ã¯æªãµãã¼ãã§ããã
https://github.com/golang/image/blob/c73c2afc3b812cdd6385de5a50616511c4a3d458/bmp/reader.go#L151
ImageMagick ã§ã¯ Windows V3
以å¤ã® BMP ãå¤æå¯è½ã§ããã®ç¹ã§ã¯ Go åãã¦å£åããé¨åã¨è¨ãã¾ããã¨ã¯ããè¿å¹´ã¯ BMP ãã¡ã¤ã«ãã¢ãããã¼ããããåæ°ã¯ãã»ã©å¤ããªãã大ããªåé¡ã«ã¯è³ã£ã¦ã¾ããã
ä»ã«ããImageMagick ã¯å£ããç»åãå¤æã§ãã ã¨ããè¬æ©è½ãããããã¡ããå£ãæ¹ã«ãä¾ãã®ã§ãããGo çã§ã¯å¤æã«å¤±æããç»åã§ã ImageMagick ã ã¨å¤æã§ãããã¨ãããã¾ãããªããããã£ãã±ã¼ã¹ã¯å ¨ä½ããè¦ãã°æ¥µå ããªã®ã§ãã®ã±ã¼ã¹ãå®ç¨ã§ã¯åé¡ç¡ãã§ãããã
éç¨å¾
ImageMagick ãå»æ¢ã Go çãµã ãã¤ã«çæãã¼ã«ãéç¨ãã¦ãããã°ããçµã¡ã¾ãããã大ããªåé¡ã¯åºã¦ãã¾ãããæã ã¯ãµã ãã¤ã«ä½æã®æåçãã¢ãã¿ãªã³ã°ãã¦ããã æåç㯠99.9% ä»è¿ãä¿ã£ã¦ãã¾ãã巨大ç»åãå£ããç»åãæ¥ãã±ã¼ã¹ãèæ ®ããã¨ååãªæåçã¨è¨ããã§ãããã
ããã§ä»¥åããä¸æ©å®å ¨ãªã¯ã©ã¦ããµã¼ãã¹ã«è¿ã¥ãããã¨æãã¾ãããç¾ç¶åãã¦ããããããã§ãããã¨ãããããªå®æãªéç¨ã§ã¯ãªããå®å ¨æ§ã確ä¿ãããããªãä½ããªãããåããªãã¨ãã姿å¢ã¯ãµã¤ãã¦ãºã®èªããã¨ããã ã¨æãã¾ãã
ã¾ããèå¼±æ§å¯¾å¿ã®å·¥æ°ãæ¸ãããã¨ããç¹ã§ãç®çãéæã§ãã¾ãããèå¼±æ§å¯¾å¿ã¯å·¥æ°ã ãã§ãªãç²¾ç¥åãæ¶èãããã®ãªã®ã§ããããã£ãé¨åã®æ¹åã¯ãµã¼ãã¹ã®å®å®éç¨ã«ç¹ããã¨æãã¾ãããã¡ãã Go åããããã¨ãã£ã¦èå¼±æ§ãç¡ããªãããã§ã¯ãªããé¢é£ããèå¼±æ§æ å ±ã¯å¼ãç¶ã注è¦ãã¦ããã¾ãã
ãµã ãã¤ã«æ©è½ã¨ãããã®ã¯ãã£ã¦å½ç¶ã§ããã¾ãç®ç«ããªãå°å³ãªæ©è½ããç¥ãã¾ãããã§ããã®è£ã§ã¯æ§ã ãªç»åãå¤æãã¦ãããè³¢ããã¼ã«ãæ´»èºãã¦ããã¦ããã®ã§ããImageMagick ã¯é·æéã«ããããµã¤ãã¦ãºã®ãµã ãã¤ã«äºæ ãæ¯ãã¦ããã¾ãããããããªã ImageMagickããã¾ã¾ã§ãµã ãã¤ã«ããããã¨ãã