堆损坏 - SEGV_MAPERR在Android原生code [英] Heap Corruption - SEGV_MAPERR in Android Native code

查看:5475
本文介绍了堆损坏 - SEGV_MAPERR在Android原生code的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图创建流AES加密一个小型图书馆,我开始根据在Facebook上隐匿的项目我的工作( HTTPS ://github.com/facebook/conceal ),只是改变了一些东西,提高各地土特产包装,支持密码与填充

I am trying to create a small library for stream AES encryption, I started my work based on Facebook Conceal project (https://github.com/facebook/conceal), just changing some things and improving the wrapper around the native to support ciphers with padding.

这是工作,它可以破译文件没有问题,但我得到随机的堆内存腐败当我和大数据流工作,很多时间调试后,我一直无法找到错误。

It is working and it can decipher files without problems but I get random Heap Memory Corruptions when I work with large streams, and after a lot of time debugging I have been unable to find the error.

下面是我的code:结果
https://gist.github.com/frisco82/9782725

Here is my code:
https://gist.github.com/frisco82/9782725

我试图找到内存分配或免费的问题,但几乎没有的malloc或免费的,JNI调用应该是安全的,同样也适用于OpenSSL的那些(我编我自己却难掩提供的人也会失败)

I have tried to find memory allocation or free problems but there are almost no malloc or free, and jni call should be safe, the same goes for openssl ones (I have compiled my own but conceal provided ones also fail)

CheckJni不会警告任何东西,虽然上下文处理有点开箱似乎没有它不坏了(确实的Andr​​oid conscrypt似乎使用类似的东西)。

CheckJni does not warn about anything and while the context handling is a bit out of the box it doesn't seem broken (indeed Android conscrypt seems to use something similar).

此外,如果有人可以点我到Android原生AES多步(多更新调用)库,我会切换到这一点,忘记这一点。

Also if someone can point me to a Android native AES multistep (multiple update calls) library I will switch to that and forget this.

的误差变化从时间到时间,但它通常是类似于他

The error varies from time to time but it is usually similar to his:

03-26 10:33:02.065: A/dalvikvm(2475): @@@ ABORTING: DALVIK: HEAP MEMORY CORRUPTION IN mspace_malloc addr=0x0
03-26 10:33:02.065: A/libc(2475): Fatal signal 11 (SIGSEGV) at 0xdeadbaad (code=1), thread 2494 (AsyncTask #1)
03-26 10:33:02.205: I/DEBUG(933): *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
03-26 10:33:02.205: I/DEBUG(933): Build fingerprint: 'generic_x86/google_sdk_x86/generic_x86:4.4.2/KK/999428:eng/test-keys'
03-26 10:33:02.205: I/DEBUG(933): Revision: '0'
03-26 10:33:02.205: I/DEBUG(933): pid: 2475, tid: 2494, name: AsyncTask #1  >>> com.proton <<<
03-26 10:33:02.205: I/DEBUG(933): signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr deadbaad

完整的堆栈跟踪:

http://pastebin.com/f6mDuQEj

推荐答案

毕竟我是能够解决此问题, EVP_C​​ipherUpdate (或JNI ReleaseByteArrayElements )有时会溢出输出缓冲器造成堆损坏,没有在我的code是错误的,也是它不与主叫方如更换问题 EVP_C​​ipherUpdate 的memcpy 用同样的参数调用和预期一样,没有堆损坏。

After all I was able to work around this problem, EVP_CipherUpdate (or jni ReleaseByteArrayElements) sometimes overflow the output buffer causing the heap corruption, nothing in my code was wrong and also it was not a problem with the caller as replacing EVP_CipherUpdate with a memcpy call with the same parameters worked as expected and there was no heap corruption.

于是溶液加入一些额外的长度发送到nativeUpdate和错误不见了输出缓冲区。

So the solution was adding some extra length to the output buffer sent to nativeUpdate and the error was gone.

我已经做出的库为他人在使用的完整工作版本:
https://github.com/frisco82/conceal

I have made the full working version of the library for others to use at: https://github.com/frisco82/conceal

这篇关于堆损坏 - SEGV_MAPERR在Android原生code的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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