sochix / TLSharp

Telegram client library implemented in C#
1.01k stars 380 forks source link

I cant get channel messages photo. Memory Fail. Authentication fail. #851

Open emreordukaya opened 5 years ago

emreordukaya commented 5 years ago

Hi I try to download and save channel message's photo via TLSharp. So I do it with this code.

int filePart = 256 * 1024;
int offset = 0;
TLFile resFile;
Image img;
using (MemoryStream ms = new MemoryStream())
{
    while (offset < ((TLPhoto)webpage.Photo).Sizes.OfType<TLPhotoSize>().Last().Size)
    {
        resFile = await client.GetFile(new TLInputFileLocation()
        {
            LocalId = tf.LocalId,
            Secret = tf.Secret,
            VolumeId = tf.VolumeId
        }, filePart, offset);
        ms.Write(resFile.Bytes, 0, resFile.Bytes.Length);
        offset += filePart;
    }                                                                        
    img = Image.FromStream(ms);
    img.Save(Path.Combine(HttpRuntime.AppDomainAppPath, "Content/images/TLimages/" + _messagePreview.MessagePreviewURL), System.Drawing.Imaging.ImageFormat.Jpeg);
    Thread.Sleep(1000);
} 

It works at lots of channel message's photo. but for one message code failing. I cant understand. It doesnt go catch block. direct go failing an I have to log in again via authentication.

This is failing channel --> https://t.me/TrinityCommunity This is failing channel message --> https://t.me/TrinityCommunity/72

I can download and save https://t.me/TrinityCommunity/179 with program automaticly. I can download and save https://t.me/TrinityCommunity/178 with program automaticly. ... ... I can download and save https://t.me/TrinityCommunity/73 with program automaticly. But I cant download and save https://t.me/TrinityCommunity/72. I run it try and catch block but program doesnt go catch block. Memory fail. waiting but doesnt answer. I restart program but authentication fails everytime.

This is image of Visual Studio Developer's output 1
so4 chemical symbol
So everything look like very normal but I cant save this photo. Can u help?

emreordukaya commented 5 years ago

This is BUG problem. BUG is about with this photo. https://t.me/TrinityCommunity/72 Ekran Alıntısı

gitcoinbot commented 5 years ago

Issue Status: 1. Open 2. Started 3. Submitted 4. Done


This issue now has a funding of 0.056 ETH (14.75 USD @ $263.32/ETH) attached to it.

kuhnchris commented 5 years ago

Did you try to initialize the MemoryStream with a (high) number? not sure if resFiles.Bytes is a byte[], but according to the help...

https://docs.microsoft.com/en-us/dotnet/api/system.io.memorystream.write?view=netframework-4.8#System_IO_MemoryStream_Write_System_Byte___System_Int32_System_Int32_ Except for a MemoryStream constructed with a byte[] parameter, write operations at the end of a MemoryStream expand the MemoryStream.

Let me know if this helps!

gitcoinbot commented 5 years ago

Issue Status: 1. Open 2. Started 3. Submitted 4. Done


Workers have applied to start work.

These users each claimed they can complete the work by 12 months from now. Please review their action plans below:

1) kuhnchris has applied to start work _(Funders only: approve worker | reject worker)_.

Maybe I can help you here, never worked with TLSharp before, but worked with C# the last 10 years, so maybe we can find a solution to your problem.

Learn more on the Gitcoin Issue Details page.

emreordukaya commented 5 years ago

hi @kuhnchris , I can approve you for this work if you can complate this work. the project get fails at this line; resFile = await client.GetFile(new TLInputFileLocation() { LocalId = tf.LocalId, Secret = tf.Secret, VolumeId = tf.VolumeId }, filePart, offset); I think client.Getfile methot try to run as an await and define TLInputFileLocation and then program go infinity loop. I dont get any error but I get out authentication. Also I have to re authent to telegram again re run the program.

gitcoinbot commented 5 years ago

@kuhnchris Hello from Gitcoin Core - are you still working on this issue? Please submit a WIP PR or comment back within the next 3 days or you will be removed from this ticket and it will be returned to an ‘Open’ status. Please let us know if you have questions!

Funders only: Snooze warnings for 1 day | 3 days | 5 days | 10 days | 100 days

emreordukaya commented 5 years ago

yes, I m still working this project. I m waiting your pulrequest. can u help me @kuhnchris

kuhnchris commented 5 years ago

hey there - there is currently a vacation day here in europe, so I'm out, but I'll return tomorrow to start working on it. I had some troubles with my VS install, so I had to postpone it. I'll let you know. By the way you did look at TLSharp-ng, right? https://github.com/Andriy1218/TLSharp

emreordukaya commented 5 years ago

I worked on https://github.com/sochix/TLSharp and get problem on this prroject.

where running this line resFile = await client.GetFile(new TLInputFileLocation() { LocalId = tf.LocalId, Secret = tf.Secret, VolumeId = tf.VolumeId }, filePart, offset);

this project (https://github.com/Andriy1218/TLSharp) if forked from (https://github.com/sochix/TLSharp) so did they fix this prblem?

kuhnchris commented 5 years ago

Maybe. I'm trying with sochix, maybe Andriy fixed this because they had same problem, NG usually means "next generation", they are also >10+ commits ahead of sochix. So maybe sochix is dead?

emreordukaya commented 5 years ago

I delete nuget of https://github.com/sochix/TLSharp then add nuget of https://github.com/Andriy1218/TLSharp to the project. then at the same point I get fail again. no error no message. resFile = await client.GetFile(new TLInputFileLocation() { LocalId = tf.LocalId, Secret = tf.Secret, VolumeId = tf.VolumeId }, filePart, offset);

kuhnchris commented 5 years ago

OK, then I will have a look at it.

gitcoinbot commented 5 years ago

@kuhnchris Hello from Gitcoin Core - are you still working on this issue? Please submit a WIP PR or comment back within the next 3 days or you will be removed from this ticket and it will be returned to an ‘Open’ status. Please let us know if you have questions!

Funders only: Snooze warnings for 1 day | 3 days | 5 days | 10 days | 100 days

emreordukaya commented 5 years ago

I debugged the project via native code instead of nuget packet. So I looked step by step. The problem i at MtProtoSender.cs file. First Recieve funct runs like as; 1 Then processMessage funct runs like as; 2

Then, at the end, HandleBadMsgNotification runs and case 16 runs end this message catched at debugger mode. 3

HandleBadMsgNotification function --> case 16 --> "msg_id too low (most likely, client time is wrong; it would be worthwhile to synchronize it using msg_id notifications and re-send the original message with the “correct” msg_id or wrap it in a container with a new msg_id if the original message had waited too long on the client to be transmitted"

can anyone pullrequest for this bug?

gitcoinbot commented 5 years ago

Issue Status: 1. Open 2. Cancelled


The funding of 0.056 ETH (15.93 USD @ $284.51/ETH) attached to this issue has been cancelled by the bounty submitter