Permalink
Browse files

FELIX-3603: make sure the JarVerifier does not skip signed META-INF e…

…ntries

git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1366310 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information...
1 parent f1ecea6 commit 819272e3d98ccac4c43873b8e75e3b97ec6e5f71 @gnodet gnodet committed Jul 27, 2012
@@ -46,13 +46,16 @@
private ByteArrayInputStream m_buffer = null;
private JarOutputStream m_output = null;
+ private static final String DUMMY_ENTRY = "__DUMMY-ENTRY__/";
+
public BundleInputStream(Content root) throws IOException
{
m_root = root;
List entries = new ArrayList();
int count = 0;
+ boolean inMetaInf = true;
String manifest = null;
for (Enumeration e = m_root.getEntries(); e.hasMoreElements();)
{
@@ -68,7 +71,8 @@ else if (entry.equalsIgnoreCase("META-INF/MANIFEST.MF"))
manifest = entry;
}
}
- else if (entry.toUpperCase().startsWith("META-INF/"))
+ else if (entry.toUpperCase().startsWith("META-INF/")
+ && entry.indexOf('/', "META-INF/".length()) < 0)
{
entries.add(count++, entry);
}
@@ -77,6 +81,7 @@ else if (entry.toUpperCase().startsWith("META-INF/"))
entries.add(entry);
}
}
+ entries.add(count++, DUMMY_ENTRY);
if (manifest == null)
{
manifest = "META-INF/MANIFEST.MF";
@@ -150,38 +155,47 @@ private void readNext(String path) throws IOException
{
m_outputBuffer.m_outBuffer = new ByteArrayOutputStream();
- InputStream in = null;
- try
+ if (path == DUMMY_ENTRY)
{
- in = m_root.getEntryAsStream(path);
-
- if (in == null)
- {
- throw new IOException("Missing entry");
- }
-
JarEntry entry = new JarEntry(path);
m_output.putNextEntry(entry);
-
- byte[] buffer = new byte[4 * 1024];
-
- for (int c = in.read(buffer); c != -1; c = in.read(buffer))
- {
- m_output.write(buffer, 0, c);
- }
}
- finally
+ else
{
- if (in != null)
+ InputStream in = null;
+ try
{
- try
+ in = m_root.getEntryAsStream(path);
+
+ if (in == null)
+ {
+ throw new IOException("Missing entry");
+ }
+
+ JarEntry entry = new JarEntry(path);
+
+ m_output.putNextEntry(entry);
+
+ byte[] buffer = new byte[4 * 1024];
+
+ for (int c = in.read(buffer); c != -1; c = in.read(buffer))
{
- in.close();
+ m_output.write(buffer, 0, c);
}
- catch (Exception ex)
+ }
+ finally
+ {
+ if (in != null)
{
- // Not much we can do
+ try
+ {
+ in.close();
+ }
+ catch (Exception ex)
+ {
+ // Not much we can do
+ }
}
}
}

0 comments on commit 819272e

Please sign in to comment.