Conversation
|
@dotnet-policy-service agree
|
|
@roman-khimov Please, could you take a look? |
|
Is the response size of NeoFS also limited? |
It should be limited by the client, but currently it's not. So the problem exists for The neofs-api-csharp Client is capable to handle such large "virtual" objects and doesn't restrict their maximum size: neo-modules/src/OracleService/Protocols/OracleNeoFSProtocol.cs Lines 97 to 101 in 4e31068 and neo-modules/src/OracleService/Protocols/OracleNeoFSProtocol.cs Lines 103 to 108 in 4e31068 Preferred solutionIdeally, to solve this problem we need a change in the neofs-api-csharp Client's API to limit the amount of data that can be read from the stream. In neofs-sdk-go it is done by returning the Another possible solutionAnother way to solve this problem without neofs-api-csharp Client's API changes is to use GetObjectPayloadRangeData combined with manually pre-checked range lenght on the |
Co-authored-by: Erik Zhang <erik@neo.org>
AnnaShaleva
left a comment
There was a problem hiding this comment.
We should also consider fixing OracleNeoFSProtocol wrt #800 (comment).
| private readonly HttpClient client = new(new HttpClientHandler() { AllowAutoRedirect = false }); | ||
| private readonly HttpClient client = new(new HttpClientHandler() { AllowAutoRedirect = false }) | ||
| { | ||
| MaxResponseContentBufferSize = OracleResponse.MaxResultSize |
There was a problem hiding this comment.
We should probably adjust the exception handler of OracleService wrt this change. Currently if the responce content exceeds OracleResponse.MaxResultSize length, the exception will be thrown by message.Content.ReadAsStringAsync(...) method:
It will be catched by the following
catch block:neo-modules/src/OracleService/OracleService.cs
Lines 361 to 368 in 4e31068
As a result, we'll have
OracleResponseCode.Error code instead of OracleResponseCode.ResponseTooLarge which is more appropriate in this case. In neo-go we return OracleResponseCode.ResponseTooLarge in this case.
There was a problem hiding this comment.
Which exception is throw?
There was a problem hiding this comment.
It's up to you to investigate which one. The documentation doesn't name it: https://learn.microsoft.com/en-us/dotnet/api/system.net.http.httpclient.maxresponsecontentbuffersize?view=net-8.0#remarks.
There was a problem hiding this comment.
@superboyiii could you test it?
@shargon Due to my test result, the same as @AnnaShaleva said. We need solve it.
@AnnaShaleva @shargon There is a stream version GetObject here https://github.com/neo-ngd/neofs-api-csharp/blob/82ca3de1d87c96a04bdf094c60c7c6039bbacf81/src/Neo.FileStorage.API/client/Client.Object.cs#LL39C9-L39C9 |
Co-authored-by: Owen Zhang <38493437+superboyiii@users.noreply.github.com>
| return (OracleResponseCode.Error, message.StatusCode.ToString()); | ||
| if (!Settings.Default.AllowedContentTypes.Contains(message.Content.Headers.ContentType.MediaType)) | ||
| return (OracleResponseCode.ContentTypeNotSupported, null); | ||
| if (!message.Content.Headers.ContentLength.HasValue || message.Content.Headers.ContentLength > OracleResponse.MaxResultSize) |
There was a problem hiding this comment.
The !message.Content.Headers.ContentLength.HasValue part of it may affect legitimate responses that fit the limit, but don't have the header for whatever reason (dynamically generated content, for example).
There was a problem hiding this comment.
We can require this header
There was a problem hiding this comment.
That'd be an artificial limitation to me. It shouldn't be hard to handle !message.Content.Headers.ContentLength.HasValue case as well, NeoGo handles both cases easily.
…-modules into add-oracle-limit
| byte[] buffer = new byte[OracleResponse.MaxResultSize]; | ||
| var stream = message.Content.ReadAsStream(cancellation); | ||
| var read = await stream.ReadAsync(buffer, 0, buffer.Length, cancellation); |
There was a problem hiding this comment.
If response stream contains more than buffer.Length bytes, then it's an error and we need to return OracleResponseCode.ResponseTooLarge code. And if I'm not mistaken, the current code will just stop reading and return a part of the response with OracleResponseCode.Success code (which isn't the desired behaviour).
There was a problem hiding this comment.
Please, check the way how it's done in neo-go: https://github.com/nspcc-dev/neo-go/blob/7b86a54fc0dd918a2514b0108be986a6e2cc63fa/pkg/services/oracle/response.go#L71-L82
AnnaShaleva
left a comment
There was a problem hiding this comment.
@shargon, could you also consider fixing the same problem for OracleNeoFSProtocol as @ZhangTao1596 suggested? #800 (comment)
Co-authored-by: Anna Shaleva <shaleva.ann@gmail.com>
|
@superboyiii could you test it? |
I'm ing... |
superboyiii
left a comment
There was a problem hiding this comment.
Request: https://api.github.com/users?since=800&per_page=1000

Works as expected!
No description provided.