Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Zip file is not closed properly #1547

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion src/main/java/com/adobe/epubcheck/ocf/OCFChecker.java
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,18 @@ public boolean apply(OPFHandler opfHandler)
//
checkFileExtension(state);

// Close zip file to free resource
if (state.getZipResources() != null)
{
try
{
state.getZipResources().close();
}
catch (Exception e)
{
// FIXME 2023 - Inability to close zip file should be handled
}
}
}

private boolean checkContainerFile(OCFCheckerState state)
Expand Down Expand Up @@ -275,7 +287,9 @@ private boolean checkContainerStructure(OCFCheckerState state)
{
// FIXME 2022 build resourcesProvider depending on MIME type
// Get a container
Iterable<OCFResource> resourcesProvider = new OCFZipResources(context.url);
OCFZipResources resourcesProvider = new OCFZipResources(context.url);
// Store the OCFZipResources object so it can be closed later
state.setZipResources(resourcesProvider);
// Set to store the normalized paths for duplicate checks
final Set<String> normalizedPaths = new HashSet<>();
// Lists to store the container entries for later empty directory check
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/com/adobe/epubcheck/ocf/OCFCheckerState.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ class OCFCheckerState
private final ImmutableList.Builder<URL> packageDocuments = ImmutableList.builder();
private URL mappingDocument;

private OCFZipResources zipResources = null;

private final Map<URL, EPUBLocation> obfuscated = new HashMap<>();
private final Map<URL, Set<PublicationType>> publicationTypes = new LinkedHashMap<>();
private final Map<URL, String> publicationIDs = new LinkedHashMap<>();
Expand Down Expand Up @@ -84,6 +86,16 @@ public void addResource(OCFResource resource)
containerNeedsRebuild = true;
}

public OCFZipResources getZipResources()
{
return zipResources;
}

public void setZipResources(OCFZipResources zipResources)
{
this.zipResources = zipResources;
}

public void addRootfile(String mediaType, URL resource)
{
Preconditions.checkNotNull(mediaType);
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/com/adobe/epubcheck/ocf/OCFZipResources.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,11 @@ public String toString()
};
}

public void close() throws IOException
{
zip.close();
}

private static String getSHAHash(ZipEntry entry, ZipFile zip)
{
try (InputStream inputStream = zip.getInputStream(entry))
Expand Down