Avoid stack overflow when fetching deeply nested comments

This commit is contained in:
Felix Ableitner 2024-09-10 14:25:10 +02:00
parent f98b15511a
commit 88703a909c
4 changed files with 20 additions and 11 deletions

3
Cargo.lock generated
View file

@ -17,8 +17,7 @@ checksum = "8f27d075294830fcab6f66e320dab524bc6d048f4a151698e153205559113772"
[[package]]
name = "activitypub_federation"
version = "0.5.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b86eea7a032da501fe07b04a83c10716ea732c45e6943d7f045bc053aca03f2a"
source = "git+https://github.com/LemmyNet/activitypub-federation-rust.git?branch=nested-comments-stack-overflow#4b94af9ea0580226aaa10a4abb004d0b8ca10eae"
dependencies = [
"activitystreams-kinds",
"actix-web",

View file

@ -100,7 +100,7 @@ lemmy_db_views = { version = "=0.19.6-beta.7", path = "./crates/db_views" }
lemmy_db_views_actor = { version = "=0.19.6-beta.7", path = "./crates/db_views_actor" }
lemmy_db_views_moderator = { version = "=0.19.6-beta.7", path = "./crates/db_views_moderator" }
lemmy_federate = { version = "=0.19.6-beta.7", path = "./crates/federate" }
activitypub_federation = { version = "0.5.8", default-features = false, features = [
activitypub_federation = { git = "https://github.com/LemmyNet/activitypub-federation-rust.git", branch = "nested-comments-stack-overflow", default-features = false, features = [
"actix-web",
] }
diesel = "2.1.6"

View file

@ -145,15 +145,25 @@ impl Object for ApubComment {
verify_domains_match(note.id.inner(), expected_domain)?;
verify_domains_match(note.attributed_to.inner(), note.id.inner())?;
verify_is_public(&note.to, &note.cc)?;
let community = note.community(context).await?;
let community = Box::pin(note.community(context)).await?;
check_apub_id_valid_with_strictness(note.id.inner(), community.local, context).await?;
Box::pin(check_apub_id_valid_with_strictness(
note.id.inner(),
community.local,
context,
))
.await?;
verify_is_remote_object(&note.id, context)?;
verify_person_in_community(&note.attributed_to, &community, context).await?;
Box::pin(verify_person_in_community(
&note.attributed_to,
&community,
context,
))
.await?;
let (post, _) = note.get_parents(context).await?;
let creator = note.attributed_to.dereference(context).await?;
let is_mod_or_admin = is_mod_or_admin(&mut context.pool(), &creator, community.id)
let (post, _) = Box::pin(note.get_parents(context)).await?;
let creator = Box::pin(note.attributed_to.dereference(context)).await?;
let is_mod_or_admin = Box::pin(is_mod_or_admin(&mut context.pool(), &creator, community.id))
.await
.is_ok();
if post.locked && !is_mod_or_admin {

View file

@ -59,8 +59,8 @@ impl Note {
context: &Data<LemmyContext>,
) -> LemmyResult<(ApubPost, Option<ApubComment>)> {
// Fetch parent comment chain in a box, otherwise it can cause a stack overflow.
let parent = Box::pin(self.in_reply_to.dereference(context).await?);
match parent.deref() {
let parent = self.in_reply_to.dereference(context).await?;
match parent {
PostOrComment::Post(p) => Ok((p.clone(), None)),
PostOrComment::Comment(c) => {
let post_id = c.post_id;