closes #103: files incorrectly padded to nearest 16 bytes

This commit is contained in:
Wizou 2022-10-26 17:33:06 +02:00
parent 49969e46cf
commit d64c5c0c1e
3 changed files with 5 additions and 4 deletions

View file

@ -177,7 +177,7 @@ var uploadedFile = await client.UploadFileAsync(@"C:\Pictures\flower.jpg");
// Photo 3 specified by external url: // Photo 3 specified by external url:
const string photoUrl = "https://picsum.photos/310/200.jpg"; const string photoUrl = "https://picsum.photos/310/200.jpg";
var inputMedias = new InputMedia[] var inputMedias = new List<InputMedia>
{ {
photoFromTelegram, // PhotoBase has implicit conversion to InputMediaPhoto photoFromTelegram, // PhotoBase has implicit conversion to InputMediaPhoto
new InputMediaUploadedPhoto { file = uploadedFile }, new InputMediaUploadedPhoto { file = uploadedFile },

View file

@ -86,7 +86,7 @@ namespace WTelegram
bool abort = false; bool abort = false;
for (long bytesLeft = length; !abort && bytesLeft != 0; file_part++) for (long bytesLeft = length; !abort && bytesLeft != 0; file_part++)
{ {
var bytes = new byte[(Math.Min(FilePartSize, bytesLeft) + 15) & ~15]; var bytes = new byte[Math.Min(FilePartSize, bytesLeft)];
read = await stream.FullReadAsync(bytes, bytes.Length, default); read = await stream.FullReadAsync(bytes, bytes.Length, default);
await _parallelTransfers.WaitAsync(); await _parallelTransfers.WaitAsync();
bytesLeft -= read; bytesLeft -= read;

View file

@ -539,6 +539,7 @@ j4WcDuXc2CTHgH8gFTNhp/Y8/SpDOhvn9QIDAQAB
else { prevBytes = new byte[32]; Array.Copy(iv, 0, prevBytes, 16, 16); Array.Copy(iv, 16, prevBytes, 0, 16); } else { prevBytes = new byte[32]; Array.Copy(iv, 0, prevBytes, 16, 16); Array.Copy(iv, 16, prevBytes, 0, 16); }
} }
public override long Length => base.Length + 15 & ~15;
public override bool CanSeek => false; public override bool CanSeek => false;
public override long Seek(long offset, SeekOrigin origin) => throw new NotSupportedException(); public override long Seek(long offset, SeekOrigin origin) => throw new NotSupportedException();
@ -549,7 +550,7 @@ j4WcDuXc2CTHgH8gFTNhp/Y8/SpDOhvn9QIDAQAB
Process(buffer, offset, count); Process(buffer, offset, count);
if (ContentLength.HasValue && _innerStream.Position == _innerStream.Length) if (ContentLength.HasValue && _innerStream.Position == _innerStream.Length)
return count - (int)(_innerStream.Position - ContentLength.Value); return count - (int)(_innerStream.Position - ContentLength.Value);
return count; return count + 15 & ~15;
} }
public override void Write(byte[] buffer, int offset, int count) public override void Write(byte[] buffer, int offset, int count)
@ -562,7 +563,7 @@ j4WcDuXc2CTHgH8gFTNhp/Y8/SpDOhvn9QIDAQAB
public void Process(byte[] buffer, int offset, int count) public void Process(byte[] buffer, int offset, int count)
{ {
count = (count + 15) & ~15; count = count + 15 & ~15;
var span = MemoryMarshal.Cast<byte, long>(buffer.AsSpan(offset, count)); var span = MemoryMarshal.Cast<byte, long>(buffer.AsSpan(offset, count));
var prev = MemoryMarshal.Cast<byte, long>(prevBytes); var prev = MemoryMarshal.Cast<byte, long>(prevBytes);
for (offset = 0, count /= 8; offset < count;) for (offset = 0, count /= 8; offset < count;)