BufferedImage漏洞 - 还有其他选择吗? [英] BufferedImage leaks - are there any alternatives?

查看:165
本文介绍了BufferedImage漏洞 - 还有其他选择吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了BufferedImage的奇怪问题,在某些情况下会占用所有免费系统内存(3GB,1.5GB免费)。

I am having strange problems with BufferedImage, which in some cases consumes all the free system memory (3GB, 1.5GB free).

我创建了一个简单的包装器我这样使用它:

I have created a simple wrapper and I use it like this:

public ImageWrapper(final byte[] bytes) throws ImageWrapperException {
    this(new ByteArrayInputStream(bytes));
}



public ImageWrapper(final ByteArrayInputStream bis) throws ImageWrapperException {
    try {
        image = ImageIO.read(bis);
        bis.close();
    } catch (IOException e) {
        throw new ImageWrapperException(e);
    }
}

(我有jsut验证即使用 image = ImageIO.read(file);

(I have jsut verified that it happens even with image = ImageIO.read(file);)

我没有得到任何例外,直到第一个无法分配内存。

I am not getting any exceptions until the first "Cannot allocate memory".

出于某种原因,在读取特定类型的图像时,图像的读取将以消耗的所有系统内存结束。我不是在讨论堆,而是系统内存。

For some reason, when reading specific type of images, the reading of the image will end up with all the system memory consumed. I am not talking about heap, but really the system memory.

它只在某些环境中发生 - 它不会发生在我的 OSX 上,但它发生在我的 Debian 服务器上。

It happens only in certain environments - it does not happen on my OSX, but it happens on my Debian server.


  1. 你知道为什么会这样吗?

  2. BufferedImage是否有其他选择,可能效果更好?

  3. 有问题的机器是虚拟服务器。它可以由它的配置引起吗?

谢谢

编辑:


  1. 示例图片: http:// cl .ly / 1P430l0V1g133r0C291J

  2. 这只是第一个也是唯一一个会产生这种情况的实例。

  3. 我刚刚确认它也是发生在: image = ImageIO.read(file); - 我开始认为,它必须是Java之外的东西 - 一些本机库是错误的......

  1. Example image: http://cl.ly/1P430l0V1g133r0C291J
  2. It is just the first and only instance which will produce this.
  3. I have just verified that it also happens with: image = ImageIO.read(file); - I am starting to think, that it must be something outside of Java - some native library which is buggy...

EDIT2:

所以问题在于FileSystem - 我在哪里有一个7GB的目录,里面有成千上万的图像。当我尝试读取文件时,它会占用所有内存 - 我想这是某种文件系统问题。

So the problem is with the FileSystem - where I have a 7GB directory with thousands of images inside. When I try to read a file, it consumes all the memory - I suppose it is some kind of Filesystem issue.

推荐答案

BufferedImage确实存在问题 - 我已经在两台服务器上测试了它并且它在泄漏时具有相同的结果 - 系统完全没有内存。

There is definitely something wrong with BufferedImage - I've tested it on two servers and it was leaking with the same results - System completely out of memory.

最后我用PHP编写了一个简单的包装器,现在我使用GD进行图像处理。现在工作正常。感谢您的所有建议!

In the end I've written a simple wrapper over PHP and I now use GD for image manipulation. Works fine now. Thanks for all the suggestions!

这篇关于BufferedImage漏洞 - 还有其他选择吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆