[OpenSmalltalk/opensmalltalk-vm] Fix #484 [Win64]Cannot save and load image files with a heap whose size is more than 0xff ff ff ff (~4.1GB) (#485)

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

[OpenSmalltalk/opensmalltalk-vm] Fix #484 [Win64]Cannot save and load image files with a heap whose size is more than 0xff ff ff ff (~4.1GB) (#485)

David T Lewis
 

The problem is actually when there is only one segment of memory of more of 0xff ff ff ff to read or to write to disk.

This fix the issue and it is tested with a real case on windows.

I added some checks on function return.

Let me know if changes are to be done to follows some conventions or optimizations.


You can view, comment on, or merge this pull request online at:

  https://github.com/OpenSmalltalk/opensmalltalk-vm/pull/485

Commit Summary

  • Fix Issue when opening heaps of more than MAX DWORD size
  • Add function return test

File Changes

Patch Links:


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or unsubscribe.

<script type="application/ld+json">[ { "@context": "http://schema.org", "@type": "EmailMessage", "potentialAction": { "@type": "ViewAction", "target": "https://github.com/OpenSmalltalk/opensmalltalk-vm/pull/485", "url": "https://github.com/OpenSmalltalk/opensmalltalk-vm/pull/485", "name": "View Pull Request" }, "description": "View this Pull Request on GitHub", "publisher": { "@type": "Organization", "name": "GitHub", "url": "https://github.com" } } ]</script>
Reply | Threaded
Open this post in threaded view
|

Re: [OpenSmalltalk/opensmalltalk-vm] Fix #484 [Win64]Cannot save and load image files with a heap whose size is more than 0xff ff ff ff (~4.1GB) (#485)

David T Lewis
 

@j4yk commented on this pull request.


In platforms/win32/plugins/FilePlugin/sqWin32FilePrims.c:

> @@ -37,6 +37,7 @@ extern struct VirtualMachine *interpreterProxy;

 

 #define true  1

 #define false 0

+static const DWORD MAX_DWORD = 4294967295;

⬇️ Suggested change
-static const DWORD MAX_DWORD = 4294967295;

+static const DWORD MAX_DWORD = MAXDWORD;


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or unsubscribe.

<script type="application/ld+json">[ { "@context": "http://schema.org", "@type": "EmailMessage", "potentialAction": { "@type": "ViewAction", "target": "https://github.com/OpenSmalltalk/opensmalltalk-vm/pull/485#pullrequestreview-391794887", "url": "https://github.com/OpenSmalltalk/opensmalltalk-vm/pull/485#pullrequestreview-391794887", "name": "View Pull Request" }, "description": "View this Pull Request on GitHub", "publisher": { "@type": "Organization", "name": "GitHub", "url": "https://github.com" } } ]</script>
Reply | Threaded
Open this post in threaded view
|

Re: [OpenSmalltalk/opensmalltalk-vm] Fix #484 [Win64]Cannot save and load image files with a heap whose size is more than 0xff ff ff ff (~4.1GB) (#485)

David T Lewis
In reply to this post by David T Lewis
 

@j4yk commented on this pull request.


In platforms/win32/plugins/FilePlugin/sqWin32FilePrims.c:

> @@ -37,6 +37,7 @@ extern struct VirtualMachine *interpreterProxy;
 
 #define true  1
 #define false 0
+static const DWORD MAX_DWORD = 4294967295;

...so really one could just use the constant provided by the Windows headers below.


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or unsubscribe.

<script type="application/ld+json">[ { "@context": "http://schema.org", "@type": "EmailMessage", "potentialAction": { "@type": "ViewAction", "target": "https://github.com/OpenSmalltalk/opensmalltalk-vm/pull/485#discussion_r407102741", "url": "https://github.com/OpenSmalltalk/opensmalltalk-vm/pull/485#discussion_r407102741", "name": "View Pull Request" }, "description": "View this Pull Request on GitHub", "publisher": { "@type": "Organization", "name": "GitHub", "url": "https://github.com" } } ]</script>
Reply | Threaded
Open this post in threaded view
|

Re: [OpenSmalltalk/opensmalltalk-vm] Fix #484 [Win64]Cannot save and load image files with a heap whose size is more than 0xff ff ff ff (~4.1GB) (#485)

David T Lewis
In reply to this post by David T Lewis
 

@j4yk commented on this pull request.


In platforms/win32/plugins/FilePlugin/sqWin32FilePrims.c:

>    position = sqImageFilePosition(h);
-  ReadFile((HANDLE)(h-1), (LPVOID) ptr, count*sz, &dwReallyRead, NULL);
-  while(dwReallyRead != (DWORD)(count*sz)) {
-    DWORD err = GetLastError();
-    if(sqMessageBox(MB_ABORTRETRYIGNORE, TEXT("Squeak Warning"),TEXT("Image file read problem (%d out of %d bytes read)"), dwReallyRead, count*sz)
-       == IDABORT) return (dwReallyRead / sz);
-    sqImageFileSeek(h, position);
-    ReadFile((HANDLE)(h-1), (LPVOID) ptr, count*sz, &dwReallyRead, NULL);
+  while (reallyRead != totalToRead) {
+    DWORD toRead = (totalToRead - reallyRead) > (size_t)MAX_DWORD ? MAX_DWORD : totalToRead - reallyRead;
+    BOOL ret = ReadFile((HANDLE)(h - 1), (LPVOID)((sqInt)ptr + (sqInt)reallyRead), toRead, &dwReallyRead, NULL);
+    reallyRead += dwReallyRead;
+
+    if (!ret | dwReallyRead != toRead) {

Not sure whether this is a bug or "clever" code to use the bitwise or. I suggest using the boolean operators (&& and ||) instead for clarity.


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or unsubscribe.

<script type="application/ld+json">[ { "@context": "http://schema.org", "@type": "EmailMessage", "potentialAction": { "@type": "ViewAction", "target": "https://github.com/OpenSmalltalk/opensmalltalk-vm/pull/485#pullrequestreview-391795210", "url": "https://github.com/OpenSmalltalk/opensmalltalk-vm/pull/485#pullrequestreview-391795210", "name": "View Pull Request" }, "description": "View this Pull Request on GitHub", "publisher": { "@type": "Organization", "name": "GitHub", "url": "https://github.com" } } ]</script>
Reply | Threaded
Open this post in threaded view
|

Re: [OpenSmalltalk/opensmalltalk-vm] Fix #484 [Win64]Cannot save and load image files with a heap whose size is more than 0xff ff ff ff (~4.1GB) (#485)

David T Lewis
In reply to this post by David T Lewis
 

@j4yk commented on this pull request.


In platforms/win32/plugins/FilePlugin/sqWin32FilePrims.c:

>    DWORD dwReallyWritten;
-  WriteFile((HANDLE)(h-1), (LPVOID) ptr, count*sz, &dwReallyWritten, NULL);
-  return (size_t) (dwReallyWritten / sz);
+  size_t totalToWrite = count * sz;
+  squeakFileOffsetType position;
+
+  position = sqImageFilePosition(h);
+  while (reallyWritten != totalToWrite) {
+    DWORD toWrite = (totalToWrite - reallyWritten) > (size_t) MAX_DWORD ? MAX_DWORD : totalToWrite - reallyWritten;
+    BOOL ret = WriteFile((HANDLE)(h - 1), (LPVOID)((sqInt)ptr + (sqInt) reallyWritten), toWrite, &dwReallyWritten, NULL);
+    reallyWritten += dwReallyWritten;
+
+    if (!ret | dwReallyWritten != toWrite) {

See above.


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or unsubscribe.

<script type="application/ld+json">[ { "@context": "http://schema.org", "@type": "EmailMessage", "potentialAction": { "@type": "ViewAction", "target": "https://github.com/OpenSmalltalk/opensmalltalk-vm/pull/485#pullrequestreview-391795361", "url": "https://github.com/OpenSmalltalk/opensmalltalk-vm/pull/485#pullrequestreview-391795361", "name": "View Pull Request" }, "description": "View this Pull Request on GitHub", "publisher": { "@type": "Organization", "name": "GitHub", "url": "https://github.com" } } ]</script>
Reply | Threaded
Open this post in threaded view
|

Re: [OpenSmalltalk/opensmalltalk-vm] Fix #484 [Win64]Cannot save and load image files with a heap whose size is more than 0xff ff ff ff (~4.1GB) (#485)

David T Lewis
In reply to this post by David T Lewis
 

@eliotmiranda approved this pull request.


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or unsubscribe.

<script type="application/ld+json">[ { "@context": "http://schema.org", "@type": "EmailMessage", "potentialAction": { "@type": "ViewAction", "target": "https://github.com/OpenSmalltalk/opensmalltalk-vm/pull/485#pullrequestreview-391795498", "url": "https://github.com/OpenSmalltalk/opensmalltalk-vm/pull/485#pullrequestreview-391795498", "name": "View Pull Request" }, "description": "View this Pull Request on GitHub", "publisher": { "@type": "Organization", "name": "GitHub", "url": "https://github.com" } } ]</script>
Reply | Threaded
Open this post in threaded view
|

Re: [OpenSmalltalk/opensmalltalk-vm] Fix #484 [Win64]Cannot save and load image files with a heap whose size is more than 0xff ff ff ff (~4.1GB) (#485)

David T Lewis
In reply to this post by David T Lewis
 

Merged #485 into Cog.


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or unsubscribe.

<script type="application/ld+json">[ { "@context": "http://schema.org", "@type": "EmailMessage", "potentialAction": { "@type": "ViewAction", "target": "https://github.com/OpenSmalltalk/opensmalltalk-vm/pull/485#event-3224425856", "url": "https://github.com/OpenSmalltalk/opensmalltalk-vm/pull/485#event-3224425856", "name": "View Pull Request" }, "description": "View this Pull Request on GitHub", "publisher": { "@type": "Organization", "name": "GitHub", "url": "https://github.com" } } ]</script>
Reply | Threaded
Open this post in threaded view
|

Re: [OpenSmalltalk/opensmalltalk-vm] Fix #484 [Win64]Cannot save and load image files with a heap whose size is more than 0xff ff ff ff (~4.1GB) (#485)

fniephaus
In reply to this post by David T Lewis
 
@Jakob: Eliot seems to have merged this without incorporating your feedback. Could you please open another PR with your suggestions?

Thanks,
Fabio

On Sat, 11 Apr 2020 at 9:46 pm, Jakob Reschke <[hidden email]> wrote:
 

@j4yk commented on this pull request.


In platforms/win32/plugins/FilePlugin/sqWin32FilePrims.c:

>    DWORD dwReallyWritten;
-  WriteFile((HANDLE)(h-1), (LPVOID) ptr, count*sz, &dwReallyWritten, NULL);
-  return (size_t) (dwReallyWritten / sz);
+  size_t totalToWrite = count * sz;
+  squeakFileOffsetType position;
+
+  position = sqImageFilePosition(h);
+  while (reallyWritten != totalToWrite) {
+    DWORD toWrite = (totalToWrite - reallyWritten) > (size_t) MAX_DWORD ? MAX_DWORD : totalToWrite - reallyWritten;
+    BOOL ret = WriteFile((HANDLE)(h - 1), (LPVOID)((sqInt)ptr + (sqInt) reallyWritten), toWrite, &dwReallyWritten, NULL);
+    reallyWritten += dwReallyWritten;
+
+    if (!ret | dwReallyWritten != toWrite) {

See above.


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or unsubscribe.

Reply | Threaded
Open this post in threaded view
|

Re: [OpenSmalltalk/opensmalltalk-vm] Fix #484 [Win64]Cannot save and load image files with a heap whose size is more than 0xff ff ff ff (~4.1GB) (#485)

David T Lewis
In reply to this post by David T Lewis
 

@VincentBlondeau commented on this pull request.


In platforms/win32/plugins/FilePlugin/sqWin32FilePrims.c:

>    position = sqImageFilePosition(h);
-  ReadFile((HANDLE)(h-1), (LPVOID) ptr, count*sz, &dwReallyRead, NULL);
-  while(dwReallyRead != (DWORD)(count*sz)) {
-    DWORD err = GetLastError();
-    if(sqMessageBox(MB_ABORTRETRYIGNORE, TEXT("Squeak Warning"),TEXT("Image file read problem (%d out of %d bytes read)"), dwReallyRead, count*sz)
-       == IDABORT) return (dwReallyRead / sz);
-    sqImageFileSeek(h, position);
-    ReadFile((HANDLE)(h-1), (LPVOID) ptr, count*sz, &dwReallyRead, NULL);
+  while (reallyRead != totalToRead) {
+    DWORD toRead = (totalToRead - reallyRead) > (size_t)MAX_DWORD ? MAX_DWORD : totalToRead - reallyRead;
+    BOOL ret = ReadFile((HANDLE)(h - 1), (LPVOID)((sqInt)ptr + (sqInt)reallyRead), toRead, &dwReallyRead, NULL);
+    reallyRead += dwReallyRead;
+
+    if (!ret | dwReallyRead != toRead) {

It is not clever code here. Thanks for spotting it!


You are receiving this because you commented.
Reply to this email directly, view it on GitHub, or unsubscribe.

<script type="application/ld+json">[ { "@context": "http://schema.org", "@type": "EmailMessage", "potentialAction": { "@type": "ViewAction", "target": "https://github.com/OpenSmalltalk/opensmalltalk-vm/pull/485#discussion_r407173808", "url": "https://github.com/OpenSmalltalk/opensmalltalk-vm/pull/485#discussion_r407173808", "name": "View Pull Request" }, "description": "View this Pull Request on GitHub", "publisher": { "@type": "Organization", "name": "GitHub", "url": "https://github.com" } } ]</script>