Don't read more than 4096 chars in FileUtils#readString

FileUtils#readString() is used to read directory path from .nomedia
file. As most of the filesystems have upper limit of 4096 chars for path
of the file, it's safe to read only 4096 bytes from the file. Adding
upper limit for readString will help in avoiding OutOfMemoryError while
reading a large renamed .nomedia file.

FileUtils#readString() is used for reading the directory path from
.nomedia file to decide if it was already scanned before.
When .nomedia file size is greater than 4096 bytes, we will not read
directory path from the .nomedia file. Instead, we will treat this file
as empty .nomedia file, and continue scanning the parent directory as
hidden directory.

Bug: 174333283
Test: atest
com.android.providers.media.util.FileUtilsTest#testString

Change-Id: Iebcb8ee0be65867dd98f3edffe3c0a0effdc9c4c
2 files changed