Skip to content

Adding an invalid .xdc to draft makes get_draft always fail #6826

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
WofWca opened this issue May 1, 2025 · 0 comments
Open

Adding an invalid .xdc to draft makes get_draft always fail #6826

WofWca opened this issue May 1, 2025 · 0 comments
Labels
bug Something is not working jsonrpc webxdc

Comments

@WofWca
Copy link
Collaborator

WofWca commented May 1, 2025

  • Operating System (Linux/Mac/Windows/iOS/Android):
  • Core Version: v1.159.3
  • Client Version: Desktop 1.57.0 (git: v1.57.0-8-g09f45d1c9)

Expected behavior

get_draft works

Actual behavior

The draft becomes corrupted and get_draft never succeeds until the .xdc attachment is removed from it, or the draft itself is removed.

Additionally, misc_send_draft also fails with anyhow: .../....xdc is not a valid webxdc file.

Steps to reproduce the problem

  1. Create an empty file.
  2. Rename it to foo.xdc.
  3. Open the messenger client
  4. Attach the said file. Don't sent the message.
  5. Switch to another chat.
  6. Switch back to the original chat.

You'll see that the composer is disabled, because the code does not expect that getDraft fails.

Screenshots

Image

Logs

Uncaught (in promise) 
{code: -1, message: 'unable to locate the end of central directory record'}
Promise.then		
(anonymous)	@	Composer.tsx:764
(anonymous)	@	Composer.tsx:797

I'm not sure whether to consider this JSON-RPC-specific, since misc_send_draft also fails.

/// Get draft for a chat, if any.
async fn get_draft(&self, account_id: u32, chat_id: u32) -> Result<Option<MessageObject>> {
let ctx = self.get_context(account_id).await?;
if let Some(draft) = ChatId::new(chat_id).get_draft(&ctx).await? {
Ok(MessageObject::from_msg_id(&ctx, draft.get_id()).await?)
} else {
Ok(None)
}
}

I believe the error happens here

let webxdc_info = if message.get_viewtype() == Viewtype::Webxdc {
Some(WebxdcMessageInfo::get_for_message(context, msg_id).await?)
} else {
None
};

The Viewtype it Webxdc because it gets set here

core/src/chat.rs

Lines 927 to 937 in ef798cd

if msg.viewtype == Viewtype::File {
if let Some((better_type, _)) = message::guess_msgtype_from_suffix(msg)
// We do not do an automatic conversion to other viewtypes here so that
// users can send images as "files" to preserve the original quality
// (usually we compress images). The remaining conversions are done by
// `prepare_msg_blob()` later.
.filter(|&(vt, _)| vt == Viewtype::Webxdc || vt == Viewtype::Vcard)
{
msg.viewtype = better_type;
}
}

but this is only based on file extension, and not on whether the .xdc file is actually valid.

I think we have to options here:

  1. In set_draft, check the validity of the file prior to setting Viewtype::Webxdc.
  2. Handle the fact that Viewtype::Webxdc messages can still have an invalid .xdc file, i.e. that get_webxdc_info can fail.

The latter seems more sensible to me, because this is similar to having an invalid image file: we'd just want to say "this is supposed to be an image, but we couldn't display it".

Related:

@WofWca WofWca added bug Something is not working jsonrpc webxdc labels May 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something is not working jsonrpc webxdc
Projects
None yet
Development

No branches or pull requests

1 participant