Skip to content

Commit ec5ca48

Browse files
committed
Make parse memory configurable and raise HTML size limit
- Raise size limit from 5 MB to 50 MB - Use DOCSRS_MAX_PARSE_MEMORY to configure the max memory, defaulting to 350 MB
1 parent cbe962b commit ec5ca48

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

src/config.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ pub struct Config {
2828
// Max size of the files served by the docs.rs frontend
2929
pub(crate) max_file_size: usize,
3030
pub(crate) max_file_size_html: usize,
31+
// The most memory that can be used to parse an HTML file
32+
pub(crate) max_parse_memory: usize,
3133
}
3234

3335
impl Config {
@@ -55,7 +57,8 @@ impl Config {
5557
github_accesstoken: maybe_env("CRATESFYI_GITHUB_ACCESSTOKEN")?,
5658

5759
max_file_size: env("DOCSRS_MAX_FILE_SIZE", 50 * 1024 * 1024)?,
58-
max_file_size_html: env("DOCSRS_MAX_FILE_SIZE_HTML", 5 * 1024 * 1024)?,
60+
max_file_size_html: env("DOCSRS_MAX_FILE_SIZE_HTML", 50 * 1024 * 1024)?,
61+
max_parse_memory: env("DOCSRS_MAX_PARSE_MEMORY", 350 * 1024 * 1024)?,
5962
})
6063
}
6164

src/utils/html.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use tera::Context;
99
/// The output is an HTML page which has not yet been UTF-8 validated.
1010
pub(crate) fn rewrite_lol(
1111
html: &[u8],
12+
max_allowed_memory_usage: usize,
1213
ctx: Context,
1314
templates: &TemplateData,
1415
) -> Result<Vec<u8>, RewritingError> {
@@ -67,7 +68,7 @@ pub(crate) fn rewrite_lol(
6768
let settings = Settings {
6869
element_content_handlers: vec![head, body],
6970
memory_settings: MemorySettings {
70-
max_allowed_memory_usage: 1024 * 1024 * 350, // 350 MB, about 1.5x as large as our current largest file
71+
max_allowed_memory_usage,
7172
..MemorySettings::default()
7273
},
7374
..Settings::default()

src/web/rustdoc.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ struct RustdocPage {
192192
}
193193

194194
impl RustdocPage {
195-
fn into_response(self, rustdoc_html: &[u8], req: &mut Request) -> IronResult<Response> {
195+
fn into_response(self, rustdoc_html: &[u8], max_parse_memory: usize, req: &mut Request) -> IronResult<Response> {
196196
use iron::{headers::ContentType, status::Status};
197197

198198
let templates = req
@@ -203,7 +203,7 @@ impl RustdocPage {
203203
// Build the page of documentation
204204
let ctx = ctry!(req, tera::Context::from_serialize(self),);
205205
// Extract the head and body of the rustdoc file so that we can insert it into our own html
206-
let html = ctry!(req, utils::rewrite_lol(rustdoc_html, ctx, templates));
206+
let html = ctry!(req, utils::rewrite_lol(rustdoc_html, max_parse_memory, ctx, templates));
207207

208208
let mut response = Response::with((Status::Ok, html));
209209
response.headers.set(ContentType::html());
@@ -382,7 +382,7 @@ pub fn rustdoc_html_server_handler(req: &mut Request) -> IronResult<Response> {
382382
is_latest_version,
383383
krate,
384384
}
385-
.into_response(&file.0.content, req)
385+
.into_response(&file.0.content, config.max_parse_memory, req)
386386
}
387387

388388
/// Checks whether the given path exists.

0 commit comments

Comments
 (0)