1
0
mirror of https://github.com/chylex/TweetDuck.git synced 2025-04-30 14:34:09 +02:00

Fix crash when the buffer for ResourceHandler is smaller than the resource

This commit is contained in:
chylex 2022-02-28 07:10:37 +01:00
parent 712bcd5a6f
commit 61cd632df6
Signed by: chylex
GPG Key ID: 4DE42C8F19A80548
3 changed files with 10 additions and 11 deletions
lib/TweetLib.Browser.CEF/Logic
linux/TweetImpl.CefGlue/Handlers/Resource
windows/TweetImpl.CefSharp/Handlers

View File

@ -10,8 +10,6 @@ public abstract class ByteArrayResourceHandlerLogic {
[SuppressMessage("ReSharper", "MemberCanBePrivate.Global")] [SuppressMessage("ReSharper", "MemberCanBePrivate.Global")]
public sealed class ByteArrayResourceHandlerLogic<TResponse> : ByteArrayResourceHandlerLogic { public sealed class ByteArrayResourceHandlerLogic<TResponse> : ByteArrayResourceHandlerLogic {
public int RemainingBytes => resource.Length - position;
private readonly ByteArrayResource resource; private readonly ByteArrayResource resource;
private readonly IResponseAdapter<TResponse> responseAdapter; private readonly IResponseAdapter<TResponse> responseAdapter;
@ -46,20 +44,21 @@ public bool Skip(long bytesToSkip, out long bytesSkipped, IDisposable callback)
return true; return true;
} }
public bool Read<T>(WriteToOut<T> write, T dataOut, int bytesToRead, out int bytesRead, IDisposable callback) { public bool Read<T>(WriteToOut<T> write, T dataOut, long maxBytesToRead, out int bytesRead, IDisposable callback) {
callback.Dispose(); callback.Dispose();
if (bytesToRead > 0) { if (maxBytesToRead == 0) {
bytesRead = 0;
}
else {
int bytesToRead = (int) Math.Min(maxBytesToRead, resource.Length - position);
write(dataOut, resource.Contents, position, bytesToRead); write(dataOut, resource.Contents, position, bytesToRead);
position += bytesToRead; position += bytesToRead;
bytesRead = bytesToRead;
} }
bytesRead = bytesToRead;
return bytesRead > 0; return bytesRead > 0;
} }
public bool Read<T>(WriteToOut<T> write, T dataOut, out int bytesRead, IDisposable callback) {
return Read(write, dataOut, RemainingBytes, out bytesRead, callback);
}
} }
} }

View File

@ -38,7 +38,7 @@ protected override bool Skip(long bytesToSkip, out long bytesSkipped, CefResourc
} }
protected override bool Read(IntPtr dataOut, int bytesToRead, out int bytesRead, CefResourceReadCallback callback) { protected override bool Read(IntPtr dataOut, int bytesToRead, out int bytesRead, CefResourceReadCallback callback) {
return logic!.Read(WriteToOut, dataOut, Math.Min(bytesToRead, logic.RemainingBytes), out bytesRead, callback); return logic!.Read(WriteToOut, dataOut, bytesToRead, out bytesRead, callback);
} }
protected override void Cancel() {} protected override void Cancel() {}

View File

@ -39,7 +39,7 @@ bool IResourceHandler.Skip(long bytesToSkip, out long bytesSkipped, IResourceSki
} }
bool IResourceHandler.Read(Stream dataOut, out int bytesRead, IResourceReadCallback callback) { bool IResourceHandler.Read(Stream dataOut, out int bytesRead, IResourceReadCallback callback) {
return logic.Read(WriteToOut, dataOut, out bytesRead, callback); return logic.Read(WriteToOut, dataOut, dataOut.Length, out bytesRead, callback);
} }
bool IResourceHandler.ProcessRequest(IRequest request, ICallback callback) { bool IResourceHandler.ProcessRequest(IRequest request, ICallback callback) {