Maybe to steal data?
When you request memory via malloc you will get a block of memory that was used by other applications or the os before. I think, it should be possible to extract valuable information (like hashes that were not properly cleaned up by password-managers and other credentials) from there, in respect to the large user-base and th computational power these companies have available.
Let's do some calculations (unfortunately in code tags, becuase RE-Ex does not have MathJax):
n be the number of memory from which malloc can choose
m be the size of the window we can search in
l be the size of the searched sequence
The amount of different positions the window can have is given by
n - m + 1.
The amount of positions, which will fully include a sequence of size
m - l + 1.
Therefore the probability, that a random chosen search window will include our sequence is
p = (m - l + 1)/(n - m + 1)
We will assume,
- that the average available memory in the smartphone is
n = 4GB
- the size of our search window is
m = 1024
- that the length of the sequence is
l = 16 (the size of an MD5-Hash)
This gives us a probability of
p = (1024 - 16 + 1)/(4e9 - 1024 + 1) ~= 2.5225e-7.
Let's do some more assumptions: Suppose the messenger has
1.5 billion users (like WhatsApp has). Let's also suppose the code sends the data
twice a day and
one thousandth of the users have an unreserved MD5 hash somewhere in memory.
That gives us a total size of
1.5e9 / 1000 * 2 = 3e6 samples to evaluate each day.
We will approximate the expected numbers of useful hashes with the normal distribution:
sigma = sqrt(3e9*2.5225e-7*(1-2.5225e-7)) ~= 27.50909 (so the approx. should yield good results)
my = 3e9*2.5525e-7 ~= 756.75
So the company will get with an certainty of 99.73% between 701 and 812 (
my-2*sigma, my+2*sigma) usable hashes each day.
Disclaimer: I am not certain how java handles memory and how plausible (and effective) this scenario is. Nor do I have used any wellfounded values - I just plugged in some pseudo-logic numbers. I give also no guarantee for the corecctness of my calculations (I never really liked statistics).
Nontheless: Feel free to play around with the values and correct me if I did some miscalculations.