From 35c161185ce42943fc8e80d8024ea94444f19c11 Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Wed, 3 Dec 2025 16:03:29 +0200 Subject: [PATCH] directdownload,tomatrix: add missing nil checks --- pkg/connector/directdownload.go | 8 ++++---- pkg/connector/tomatrix.go | 8 ++++++-- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/pkg/connector/directdownload.go b/pkg/connector/directdownload.go index 5b9f9b00..a525fe89 100644 --- a/pkg/connector/directdownload.go +++ b/pkg/connector/directdownload.go @@ -191,10 +191,10 @@ func (tc *TelegramConnector) Download(ctx context.Context, mediaID networkid.Med chatFull, ok := fullChat.FullChat.(*tg.ChatFull) if !ok { return nil, fmt.Errorf("full chat is %T not *tg.ChatFull", fullChat.FullChat) - } - - // FIXME: this is basically a not found error - if photoID := chatFull.ChatPhoto.GetID(); photoID != info.ID { + } else if chatFull.ChatPhoto == nil { + // FIXME: these 2 are basically not found errors + return nil, fmt.Errorf("photo not found on chat") + } else if photoID := chatFull.ChatPhoto.GetID(); photoID != info.ID { return nil, fmt.Errorf("photo id mismatch: %d != %d", photoID, info.ID) } diff --git a/pkg/connector/tomatrix.go b/pkg/connector/tomatrix.go index 3ebfcd15..19e151a2 100644 --- a/pkg/connector/tomatrix.go +++ b/pkg/connector/tomatrix.go @@ -400,8 +400,12 @@ func (c *TelegramClient) convertMediaRequiringUpload(ctx context.Context, portal } else { content.Body = "image" } - telegramMediaID = msgMedia.Photo.GetID() - mediaTransferer = transferer.WithPhoto(msgMedia.Photo) + photo, ok := msgMedia.Photo.(*tg.Photo) + if !ok { + return nil, nil, fmt.Errorf("unrecognized photo type %T", msgMedia.Photo) + } + telegramMediaID = photo.GetID() + mediaTransferer = transferer.WithPhoto(photo) case *tg.MessageMediaDocument: document, ok := msgMedia.Document.(*tg.Document) if !ok {