mirror of
https://github.com/hrydgard/ppsspp.git
synced 2026-10-01 14:58:14 +00:00
naett: Stop the transfer when the body writer fails it
Found reviewing the commits before this one. On Windows a short write marked the request complete and then queued another read regardless, which is worse than it sounds: the caller is free to close a response the moment it sees complete, so WinHTTP carried on writing into memory that was being freed. It also meant cancelling didn't actually stop anything there. Stop at that point, and ignore anything raised after the request is complete. The Apple callbacks do the same check, so the cancellation we ask for after a failed write doesn't overwrite the error that caused it. naettMake only asserted that its request was non-NULL, and the request constructors do return NULL when a platform can't set one up - an unparseable URL is enough on Windows. Asserts are compiled out in release, so that was a null dereference. It returns NULL now, and HTTPSRequest checks for it and fails the request instead of handing it on. Also: a request cancelled between construction and Start() didn't carry that into the sink, and -1000 - our own cancellation code, not naett's - was logging "Unhandled naett error" on a perfectly normal cancel.
This commit is contained in:
1 parent
b120f0004f
commit
bc095c5e31
5 files changed
+69
-3
No files matched your search
@@ -107,3 +107,12 @@ Keep this list up to date - it's what makes it possible to move to a newer upstr
|
||||
the data just keeps arriving.
|
||||
- `naett.h`: documented what the body writer's return value means, since three of the four
|
||||
backends' behaviour depends on it.
|
||||
- `src/naett_win.c`: a short write from the body writer marked the request complete and then
|
||||
queued another read anyway, so the transfer carried on and WinHTTP kept writing into a
|
||||
response the caller was by then free to close. It stops there now, and the callback returns
|
||||
early for anything raised after the request is complete.
|
||||
- `src/naett_core.c`: `naettMake` only asserted that the request wasn't NULL, and the request
|
||||
constructors return NULL when the platform can't set one up - a URL it can't parse, say. In a
|
||||
release build that walked into a null dereference. Returns NULL instead.
|
||||
- `src/naett_osx.c`: the delegate callbacks ignore a response that's already complete, so a
|
||||
cancellation we asked for doesn't overwrite the error that caused it.
|
||||
@@ -310,6 +310,12 @@ naettReq* naettRequestWithOptions(const char* url, int numOptions, const naettOp
|
||||
naettRes* naettMake(naettReq* request) {
|
||||
assert(initialized);
|
||||
assert(request != NULL);
|
||||
// PPSSPP: naettRequest* returns NULL when the platform can't set the request up - a URL it
|
||||
// can't parse, most likely - and the assert above is compiled out in release, so this used to
|
||||
// walk straight into a null dereference.
|
||||
if (request == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
InternalRequest* req = (InternalRequest*)request;
|
||||
naettAlloc(InternalResponse, res);
|
||||
|
||||
@@ -100,7 +100,8 @@ void didReceiveData(id self, SEL _sel, id session, id dataTask, id data) {
|
||||
object_getInstanceVariable(self, "response", (void**)&res);
|
||||
// PPSSPP: didComplete already checked this; this one didn't, and the delegate outlives the
|
||||
// response when a session is invalidated.
|
||||
if (res == NULL) {
|
||||
if (res == NULL || res->complete) {
|
||||
// PPSSPP: once complete, the caller may already be closing this - don't touch it further.
|
||||
release(p);
|
||||
return;
|
||||
}
|
||||
@@ -174,6 +175,11 @@ static void didComplete(id self, SEL _sel, id session, id dataTask, id error) {
|
||||
InternalResponse* res = NULL;
|
||||
object_getInstanceVariable(self, "response", (void**)&res);
|
||||
if (res != NULL) {
|
||||
// PPSSPP: if we already failed the request - a writer that wouldn't take the data, say -
|
||||
// that's the reason we want reported, not the cancellation it caused.
|
||||
if (res->complete) {
|
||||
return;
|
||||
}
|
||||
if (error != nil) {
|
||||
res->code = naettConnectionError;
|
||||
}
|
||||
|
||||
@@ -111,6 +111,13 @@ static void CALLBACK
|
||||
callback(HINTERNET request, DWORD_PTR context, DWORD status, LPVOID statusInformation, DWORD statusInfoLength) {
|
||||
InternalResponse* res = (InternalResponse*)context;
|
||||
|
||||
// PPSSPP: once we've reported the request as complete the caller is free to close it, so
|
||||
// don't start any more I/O against it - anything still in flight would be writing into a
|
||||
// response that's being freed.
|
||||
if (res->complete) {
|
||||
return;
|
||||
}
|
||||
|
||||
switch (status) {
|
||||
case WINHTTP_CALLBACK_STATUS_HEADERS_AVAILABLE: {
|
||||
// PPSSPP: the sizing call only fills in bufSize when it fails with
|
||||
@@ -177,9 +184,17 @@ callback(HINTERNET request, DWORD_PTR context, DWORD status, LPVOID statusInform
|
||||
size_t bytesRead = statusInfoLength;
|
||||
|
||||
InternalRequest* req = res->request;
|
||||
if (req == NULL) {
|
||||
return;
|
||||
}
|
||||
if (req->options.bodyWriter(res->buffer, (int)bytesRead, req->options.bodyWriterData) != bytesRead) {
|
||||
// PPSSPP: the writer failed the request - it couldn't grow, or the caller is
|
||||
// cancelling. Upstream marked it complete and then queued another read anyway,
|
||||
// which both kept the transfer running and left WinHTTP writing into a response
|
||||
// the caller was by then free to close.
|
||||
res->code = naettReadError;
|
||||
res->complete = 1;
|
||||
break;
|
||||
}
|
||||
res->totalBytesRead += (int)bytesRead;
|
||||
// PPSSPP: bytesLeft is unsigned, so a read longer than announced used to wrap it
|
||||
|
||||
Reference in new issue
Block a user