Skip to content
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
3 changes: 2 additions & 1 deletion src/Platform_Core/org/lobobrowser/request/CacheInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectInputStream;
import java.io.Serializable;
import java.net.URL;
import java.net.URLConnection;
import java.util.logging.Level;
Expand Down Expand Up @@ -172,7 +173,7 @@ public Object getPersistentObject(final ClassLoader classLoader) {

try (
final InputStream in = new ByteArrayInputStream(content);
final ObjectInputStream oin = new ClassLoaderObjectInputStream(in, classLoader);) {
final ObjectInputStream oin = new ClassLoaderObjectInputStream(in, classLoader,Serializable.class);) {
return oin.readObject();
}
} catch (final IOException ioe) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,44 @@

import java.io.IOException;
import java.io.InputStream;
import java.io.InvalidClassException;
import java.io.ObjectInputStream;
import java.io.ObjectStreamClass;

public class ClassLoaderObjectInputStream extends ObjectInputStream {

private final ClassLoader classLoader;
private final Class<?> expectedClass;

public ClassLoaderObjectInputStream(
final InputStream in,
final ClassLoader classLoader) throws IOException {
this(in, classLoader, null);
}

public ClassLoaderObjectInputStream(final InputStream in, final ClassLoader classLoader) throws IOException {
public ClassLoaderObjectInputStream(
final InputStream in,
final ClassLoader classLoader,
final Class<?> expectedClass) throws IOException {
super(in);
this.classLoader = classLoader;
this.expectedClass = expectedClass;
}

@Override
protected Class<?> resolveClass(final ObjectStreamClass desc) throws IOException, ClassNotFoundException {
return Class.forName(desc.getName(), false, this.classLoader);
protected Class<?> resolveClass(final ObjectStreamClass desc)
throws IOException, ClassNotFoundException {

Class<?> resolved =
Class.forName(desc.getName(), false, this.classLoader);

if (expectedClass != null && !expectedClass.isAssignableFrom(resolved)) {
throw new InvalidClassException(
"Unexpected class during deserialization",
desc.getName()
);
}

return resolved;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ public Object retrieveObject(final String path, final ClassLoader classLoader) t
final ManagedFile file = this.getManagedFile(path);
try (
final InputStream in = file.openInputStream();
final ObjectInputStream oin = new ClassLoaderObjectInputStream(in, classLoader)) {
final ObjectInputStream oin = new ClassLoaderObjectInputStream(in, classLoader, Serializable.class)) {
return oin.readObject();
} catch (final FileNotFoundException err) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ public Serializable retrieveSettings(final String name, final ClassLoader classL
try (
final InputStream in = new FileInputStream(file);
final BufferedInputStream bin = new BufferedInputStream(in);
final ObjectInputStream ois = new ClassLoaderObjectInputStream(bin, classLoader);) {
final ObjectInputStream ois = new ClassLoaderObjectInputStream(bin, classLoader, Serializable.class);) {
return (Serializable) ois.readObject();
} catch (final InvalidClassException ice) {
ice.printStackTrace();
Expand Down