libpng: Remote execution of arbitrary code

libpng中发现了一个空指针引用漏洞,在特定条件下可能导致远程攻击者执行任意代码。此漏洞存在于png_push_save_buffer函数中,受影响版本包括<1.6.27等。libpng-1.6.27及后续版本已修复该漏洞。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

A null pointer dereference in libpng might allow remote attackers to execute arbitrary code.

Affected Packages
Package media-libs/libpng on all architectures

contentversion
Affected versions< 1.6.27
Unaffected versions>= 1.6.27
>= 1.5.28
>= 1.4.20
>= 1.2.57
>= 1.0.67

Background
libpng is a standard library used to process PNG (Portable Network Graphics) images. It is used by several programs, including web browsers and potentially server processes.

Description
A null pointer dereference was discovered in libpng in the png_push_save_buffer function. In order to be vulnerable, an application has to load a text chunk into the PNG structure, then delete all text, then add another text chunk to the same PNG structure, which seems to be an unlikely sequence, but it is possible.

Impact
A remote attacker, by enticing a user to process a specially crafted PNG file, could execute arbitrary code with the privileges of the process.

libpng-1.6.27 has been released to fix an old NULL pointer dereference
bug in png_set_text_2() discovered and patched by Patrick Keshishian.

New releases of legacy branches (1.0.67, 1.2.57, 1.4.20, and 1.5.28) have
also been released. Other versions can be patched by adding a single
line

  info_ptr->max_text = 0;

at the appropriate spot in png.c.

The potential “NULL dereference” bug that has existed in libpng
since version 0.71 of June 26, 1995. To be vulnerable, an application
has to load a text chunk into the png structure, then delete all text, then
add another text chunk to the same png structure, which seems to be
an unlikely sequence, but it has happened.

Applications that I have looked at (firefox, imagemagick, graphicsmagick,
pngcrush) do not appear to be vulnerable.

https://security.gentoo.org/glsa/201701-74
http://www.openwall.com/lists/oss-security/2016/12/29/2

### C语言中libpng警告`iCCP: known incorrect sRGB profile`的原因 此警告的根本原因是某些PNG图像文件中的`sRGB`配置文件存在错误或不符合标准。具体来说,`libpng`库在解析这些PNG文件时发现其内部嵌入的国际色彩联盟(ICC)配置文件存在问题[^1]。这种问题可能源于图像编辑软件生成的PNG文件未严格遵循`sRGB`规范。 当使用C语言调用`libpng`库来读取此类PNG文件时,如果启用了警告功能,则会出现上述消息。尽管这只是一个警告而非致命错误,但它可能会干扰程序的日志记录或其他正常操作流程[^3]。 ### 解决方法概述 #### 方法一:修正原始图片的颜色空间 最根本的方法是对有问题的PNG文件进行预处理,使其符合标准。可以通过专门的图形处理工具调整图像的颜色配置文件: - **ImageMagick**: 使用命令行工具`convert`将图片重新编码并移除潜在的问题配置文件。 ```bash convert input.png -strip output.png ``` - **pngcrush**: 此工具能够优化PNG文件的同时修复常见的元数据问题。 ```bash pngcrush -rem alla -reduce input.png output.png ``` 这两种方式都可以有效去除可能导致警告的信息,从而避免运行期间触发警告[^4]。 #### 方法二:升级libpng版本 确保使用的`libpng`库是最新的稳定版。较新的版本往往已经修补了许多已知缺陷,并改进了对非标准输入的兼容性和健壮性。对于开发者而言,在构建阶段指定更高版本的依赖项是一个可行的选择: ```bash pip install --upgrade libpng ``` 虽然这条指令适用于Python环境下的包管理器pip,但在C/C++环境下同样建议手动下载最新源码编译安装[^3]。 #### 方法三:忽略特定警告 (仅限必要情况) 如果不希望更改现有资源又无法更新第三方库,还可以考虑抑制这类特定类型的警告输出。不过这种方法治标不治本,应谨慎采用。例如设置自定义回调函数过滤掉不需要的消息: ```c #include <stdio.h> #include <stdlib.h> #include <png.h> void custom_warning_fn(png_structp png_ptr, png_const_charp warning_msg){ /* Ignore the specific ICC Profile related warnings */ if(strstr(warning_msg,"known incorrect sRGB profile")==NULL){ fprintf(stderr,"%s\n",warning_msg); } } int main(){ png_structp png_ptr; png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING,NULL,(png_error_ptr)NULL,&custom_warning_fn); // Continue with normal PNG reading operations... return EXIT_SUCCESS; } ``` 以上代码片段展示了如何创建一个定制化的警告处理器,它会选择性跳过关于“incorrect sRGB”的通知[^5]。 ### 总结 综上所述,针对`libpng warning: iCCP: known incorrect sRGB profile`这一现象,推荐优先采取措施纠正源头素材的质量;其次才是探索其他变通手段如屏蔽冗余日志或是替换基础组件至更先进的实现形式。 问题
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值