title: Android: Strange behavior of DocumentFile InputStream
body: <h2>Background</h2>
  
  <p>I have an application that uses Storage Access Framework.</p>
  
  <p>It prompts a user to pick a directory to obtain permissions to work with files:</p>
  
  <pre><code>Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE);
  </code></pre>
  
  <p>Then allow user to select a JPG image in the directory:</p>
  
  <pre><code>DocumentFile pickedDir = DocumentFile.fromTreeUri(this, treeUri);
  DocumentFile[] files = pickedDir.listFiles();
  ...
  DocumentFile file = files[0]; // for example
  </code></pre>
  
  <h2>Problem</h2>
  
  <p>One user has the following problem on Android 7.</p>
  
  <p>When the program try to read the content of the file (JPEG image):</p>
  
  <pre><code>InputStream is = getContentResolver().openInputStream(file.getUri());
  ... // then read the stream in a standard way
  </code></pre>
  
  <p>The content is not the true content of the file, but some random garbage with word "CONSOLE" followed by zeros:</p>
  
  <p><a href="https://i.stack.imgur.com/pc5qC.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/pc5qC.png" alt="enter image description here"></a></p>
  
  <p>The file has the correct length and no error is risen, only the content is nonsense.</p>
  
  <p>This behavior is unique and it's not reproducible on any other device.</p>
  
  <p>Has anyone encounter anything like this?</p>