Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are possible reasons for binary files corruption on android devices

Recently I'm investigating reasons for binary file corruption. Specificly, we have an android app, the native part can read/write binary file on SD card. Sometimes, the binary file corrupts for unknown reasons. We have collected some of these files from different users, and found some interesting facts.

One majority kind of corruption is that, the first 4096 bytes of the binary file are erased. When I hexdump these files, the first 4096 bytes are all zeros. Not more than 4096 or less than 4096, but exactly 4096 bytes. I think this is not coincidence. I know 4096 bytes is one page size. But lacking experience, I cannot figure out the reason, and more importantly, I don't know how to avoid such things for other users/devices.

Besides that, in the middle of some binary files, there are also some continuous zeros segments, which it shouldn't be there. If it is not our programmes' bug, is there any possible reasons which may related to platform/device kernel, or anything else like device suddenly out of power?

I hope anyone who have experienced similar situations can give me some hint/advice/solutions etc. This really confused me a lot.

Many thanks~

like image 972
songlj Avatar asked Jan 26 '16 06:01

songlj


People also ask

Why do files get corrupted on Android?

There are so many reasons behind a corrupted video file on an Android phone such as viruses, camera crashes, insufficient storage, cache, low battery, etc.

What causes files to become corrupt?

File corruption usually happens when there is an issue during the 'save' process. If your computer crashes the file being saved will likely be corrupted. Another cause might be damaged sections of your hard drive or storage media that might have viruses and malware.

How do you tell if my phone is corrupted?

Symptoms of corrupted Android OS files may include apps that fail to run properly or functions that cease to work. One example of such behavior is if your Contacts list no longer opens when you tap the “People” icon.


1 Answers

I have some simmilar experience in some embedded applications that corrupt binaries. First of all, double check your file handling (specially in multithreading environments), I can imagine you have done it thoroughly. Then, try to sync all the writings. The linux kernel doesn't write as you command your app to write, but buffers data before flushing to disk.

http://linux.die.net/man/2/sync

Hope this helps.

like image 106
Nikilator Avatar answered Sep 22 '22 03:09

Nikilator