Skip to content

Commit 0e54caa

Browse files
author
Daniel Kroening
committed
remove java_class_loader_limitt from jar_filet
1 parent 6f72b3b commit 0e54caa

File tree

3 files changed

+24
-19
lines changed

3 files changed

+24
-19
lines changed

jbmc/src/java_bytecode/jar_file.cpp

+9-10
Original file line numberDiff line numberDiff line change
@@ -16,44 +16,43 @@ Author: Diffblue Ltd
1616

1717
#include "java_class_loader_limit.h"
1818

19-
void jar_filet::initialize_file_index(java_class_loader_limitt &limit)
19+
void jar_filet::initialize_file_index()
2020
{
2121
const size_t file_count=m_zip_archive.get_num_files();
2222
for(size_t index=0; index<file_count; index++)
2323
{
2424
const auto filename=m_zip_archive.get_filename(index);
25-
if(!has_suffix(filename, ".class") || limit.load_class_file(filename))
26-
m_name_to_index.emplace(filename, index);
25+
m_name_to_index.emplace(filename, index);
2726
}
2827
}
2928

3029
/// This constructor creates a jar_file object whose contents
3130
/// are extracted from a file with given name.
3231
jar_filet::jar_filet(
33-
java_class_loader_limitt &limit,
3432
const std::string &filename):
3533
m_zip_archive(filename)
3634
{
37-
initialize_file_index(limit);
35+
initialize_file_index();
3836
}
3937

4038
/// This constructor creates a jar_file object whose contents
4139
/// are extracted from a memory buffer (byte array) as opposed
4240
/// to a jar file.
4341
jar_filet::jar_filet(
44-
java_class_loader_limitt &limit,
4542
const void *data,
4643
size_t size):
4744
m_zip_archive(data, size)
4845
{
49-
initialize_file_index(limit);
46+
initialize_file_index();
5047
}
5148

5249
// VS: No default move constructors or assigns
5350

54-
jar_filet::jar_filet(jar_filet &&other):
55-
m_zip_archive(std::move(other.m_zip_archive)),
56-
m_name_to_index((other.m_name_to_index)) {}
51+
jar_filet::jar_filet(jar_filet &&other)
52+
: m_zip_archive(std::move(other.m_zip_archive)),
53+
m_name_to_index(std::move(other.m_name_to_index))
54+
{
55+
}
5756

5857
jar_filet &jar_filet::operator=(jar_filet &&other)
5958
{

jbmc/src/java_bytecode/jar_file.h

+3-7
Original file line numberDiff line numberDiff line change
@@ -18,24 +18,20 @@ Author: Diffblue Ltd
1818

1919
#include "mz_zip_archive.h"
2020

21-
class java_class_loader_limitt;
22-
2321
/// Class representing a .jar archive
2422
class jar_filet final
2523
{
2624
public:
2725
/// Open java file for reading.
28-
/// \param limit Object limiting number of loaded .class files
2926
/// \param filename Name of the file
3027
/// \throw Throws std::runtime_error if file cannot be opened
31-
jar_filet(java_class_loader_limitt &limit, const std::string &filename);
28+
explicit jar_filet(const std::string &filename);
3229

3330
/// Open a JAR file of size \p size loaded in memory at address \p data.
34-
/// \param limit Object limiting number of loaded .class files
3531
/// \param data memory buffer with the contents of the jar file
3632
/// \param size size of the memory buffer
3733
/// \throw Throws std::runtime_error if file cannot be opened
38-
jar_filet(java_class_loader_limitt &limit, const void *data, size_t size);
34+
jar_filet(const void *data, size_t size);
3935

4036
jar_filet(const jar_filet &)=delete;
4137
jar_filet &operator=(const jar_filet &)=delete;
@@ -57,7 +53,7 @@ class jar_filet final
5753
private:
5854
/// Loads the fileindex (m_name_to_index) with a map of loaded files to
5955
/// indices.
60-
void initialize_file_index(java_class_loader_limitt &limit);
56+
void initialize_file_index();
6157

6258
mz_zip_archivet m_zip_archive;
6359

jbmc/src/java_bytecode/java_class_loader.cpp

+12-2
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,16 @@ java_class_loadert::get_parse_tree(
116116
parse_tree_with_overlayst &parse_trees = class_map[class_name];
117117
PRECONDITION(parse_trees.empty());
118118

119+
// do we refuse to load?
120+
if(!class_loader_limit.load_class_file(class_name_to_file(class_name)))
121+
{
122+
debug() << "not loading " << class_name << " because of limit" << eom;
123+
java_bytecode_parse_treet parse_tree;
124+
parse_tree.parsed_class.name = class_name;
125+
parse_trees.push_back(std::move(parse_tree));
126+
return parse_trees;
127+
}
128+
119129
// First add all given JAR files
120130
for(const auto &jar_file : jar_files)
121131
{
@@ -328,7 +338,7 @@ jar_filet &java_class_loadert::jar_pool(
328338
if(it==m_archives.end())
329339
{
330340
// VS: Can't construct in place
331-
auto file=jar_filet(class_loader_limit, file_name);
341+
auto file = jar_filet(file_name);
332342
return m_archives.emplace(file_name, std::move(file)).first->second;
333343
}
334344
else
@@ -345,7 +355,7 @@ jar_filet &java_class_loadert::jar_pool(
345355
if(it==m_archives.end())
346356
{
347357
// VS: Can't construct in place
348-
auto file=jar_filet(class_loader_limit, pmem, size);
358+
auto file = jar_filet(pmem, size);
349359
return m_archives.emplace(buffer_name, std::move(file)).first->second;
350360
}
351361
else

0 commit comments

Comments
 (0)