[Fixed] Client crash on autosave - proposed fix

14 June 2019 02:54

...

I accidentally deleted the post, sorry

dP

14 June 2019 09:47

Oh, I thought I fixed that, thanks for reporting! Will include in 1.9.2 or mb sooner if that doesn't come.

P.S. Sorry, I accidentally edited your post. I'll try to restore it but even if I don't it's ok, I'll remember this issue and definitely fix it.

14 June 2019 21:46

Cool, let me repost the patch.

Bug: buffer over-read of the data returned from CM_EncodeData.

diff -rNub a/openttd-1.9.1/src/saveload/storage_sl.cpp b/openttd-1.9.1/src/saveload/storage_sl.cpp
--- a/openttd-1.9.1/src/saveload/storage_sl.cpp 2019-04-08 13:50:04.000000000 -0700
+++ b/openttd-1.9.1/src/saveload/storage_sl.cpp 2019-06-13 16:38:38.756802300 -0700
@@ -89,6 +89,10 @@
    int n_chunks = (data.size() + 1023) / 1024;
    for (int i = 0; i < n_chunks; i++, ptr += 1024) {
        _desc[1].address = (void *)ptr;
+        if (i == n_chunks - 1) {
+            // CM_EncodeData() pads data.size() to be divisible by 64, so no remainder.
+            _desc[1].length = (data.size() % 1024) / sizeof(uint32);
+        }
        SlSetArrayIndex(index + i);
        SlGlobList(_desc);
    }

Thanks for your massive work on city builders dP!