Bug 580258 - LFS: SmudgeFilter fails with compressed content streams
Summary: LFS: SmudgeFilter fails with compressed content streams
Status: NEW
Alias: None
Product: JGit
Classification: Technology
Component: JGit (show other bugs)
Version: 6.2   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2022-06-24 07:58 EDT by Rene Pfeuffer CLA
Modified: 2022-08-06 11:57 EDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Rene Pfeuffer CLA 2022-06-24 07:58:13 EDT
The class org.eclipse.jgit.lfs.SmudgeFilter uses the function org.eclipse.jgit.lfs.internal.LfsConnectionFactory#getLfsContentConnection to create the http request to read the lfs content. In this method, at the end the accepted encoding is set to 'gzip' (https://git.eclipse.org/c/jgit/jgit.git/tree/org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/internal/LfsConnectionFactory.java?h=v6.2.0.202206011217-rc1#n234).

But if the server responds with a compressed stream, this is not decompressed by the SmudgeFilter. Therefore, the SmudgeFilter will read insufficient bytes and fails here with an IOException: https://git.eclipse.org/c/jgit/jgit.git/tree/org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/SmudgeFilter.java?h=v6.2.0.202206011217-rc1#n206

To solve this, either the connection factory should not set the accept header, or the smudge filter should inspect the content encoding header with something like this and process the resulting stream:

private static InputStream getInputStream(HttpConnection contentServerConn, InputStream contentIn) throws IOException {
  if (ENCODING_GZIP.equals(contentServerConn.getHeaderField(HDR_CONTENT_ENCODING))) {
    return new GZIPInputStream(contentIn);
  }
  return contentIn;
}
Comment 1 Thomas Wolf CLA 2022-08-06 11:57:26 EDT
Sounds good. Can you push the fix to Gerrit? See [1] for info on contributing.

[1] https://wiki.eclipse.org/EGit/Contributor_Guide#Contributing_Patches