Limit size of documents to 100 KB

This commit is contained in:
Eric Zhang 2021-06-04 15:05:24 -05:00
parent 8def441972
commit 9a0692f9ff
2 changed files with 42 additions and 0 deletions

View file

@ -240,6 +240,12 @@ impl Rustpad {
for history_op in &state.operations[revision..] {
operation = operation.transform(&history_op.operation)?.0;
}
if operation.target_len() > 100000 {
bail!(
"target length {} is greater than 100 KB maximum",
operation.target_len()
);
}
let new_text = operation.apply(&state.text)?;
let mut state = RwLockUpgradableReadGuard::upgrade(state);
state.operations.push(UserOperation { id, operation });

View file

@ -70,3 +70,39 @@ async fn test_lost_wakeups() -> Result<()> {
Ok(())
}
#[tokio::test]
async fn test_large_document() -> Result<()> {
pretty_env_logger::try_init().ok();
let filter = server();
expect_text(&filter, "stress", "").await;
let mut client = connect(&filter, "stress").await?;
let msg = client.recv().await?;
assert_eq!(msg, json!({ "Identity": 0 }));
let mut operation = OperationSeq::default();
operation.insert(&"a".repeat(5000));
let msg = json!({
"Edit": {
"revision": 0,
"operation": operation
}
});
client.send(&msg).await;
client.recv().await?;
let mut operation = OperationSeq::default();
operation.insert(&"a".repeat(500000));
let msg = json!({
"Edit": {
"revision": 0,
"operation": operation
}
});
client.send(&msg).await;
client.recv_closed().await?;
Ok(())
}