Author Topic: Corrupted executable generated.  (Read 1442 times)

0 Members and 1 Guest are viewing this topic.

Brian Alvarez

  • Hero Member
  • *****
  • Posts: 537
    • PluriBASIC
Corrupted executable generated.
« on: September 27, 2019, 10:46:32 PM »
I have a CGI script in PluriBASIC with this code:

Code: [Select]
#COMPILE cgi
'#COMPILER pbwin
#COMPILER OXYGEN
#project "nbson"
#OPTIONS X64 developer localtest
#DIM ALL
#DATABASE closed
#TIMELIMIT 10

#FORM Upload, "upload.html"

FUNCTION PBMAIN() AS LONG

select case getfield("action")
    case "upload"
        stdout "Temporary file is at:<br>"
        stdout cgi.TempName("fileToUpload") & "<br>"
        stdout "<br>"
        stdout "Remote Name:<br>"
        stdout cgi.FileName("fileToUpload") & "<br>"
        stdout "<br>"
        stdout "Extension:<br>"         
        stdout cgi.FileExt("fileToUpload") & "<br>"
        stdout str$(cgi.FileError("fileToUpload")) & "<br>"
        stdout formfield("fileToUpload") ' outputs the whole file contents.
               
        stdout "uploaded"
   
    case else
        call formout(Upload)
   
end select   

END FUNCTION

Which translates to attached source code 1, wich oxygen compiles correctly and runs very well.

When i remark the line:

Code: [Select]
stdout formfield("fileToUpload") ' outputs the whole file contents.
It translates to attached source code 2, which oxygen compiles as a corrupted executable that doesnt run.



Charles Pegge

  • Admin Support Member
  • *****
  • Posts: 4246
    • Oxygen Basic
Re: Corrupted executable generated.
« Reply #1 on: September 28, 2019, 03:24:57 AM »
Hi Brian,

Using o2 version 0.2.8, I was able to compile & run version2 without corruption.

However, I noticed you have some arrays dimensioned [ 0 ] while using indexbase 1 by default. This may be the primary cause.

Code: [Select]
'Generated with PluriBASIC 6.0.6.293216

'cp test 12:15 28/09/2019

$ filename "forms.exe"
uses rtl64
%NoConsole
uses console
uses forms.res
indexbase 0
...

Brian Alvarez

  • Hero Member
  • *****
  • Posts: 537
    • PluriBASIC
Re: Corrupted executable generated.
« Reply #2 on: September 28, 2019, 09:21:02 AM »
Those arrays are not used. The engine generates only the positive indexes for used tokens,
and for using them it generates base 1 code.

Anyway, you know best, but the problem occurs since before including token variables. Even
if the array base was the issue, i doubt it would lead to executable not being initialized correctly...
would it? or would it be so consistently intermitent? would adding or reomving random code fix it?
I suspect it is some kind of header alignment issue...

 I updated yesterday, my version is 0.2.3, where do i get 2.3.8?

  Iam attaching the damaged executable so you can examine it if you wish.
« Last Edit: September 29, 2019, 06:44:05 AM by Brian Alvarez »

Brian Alvarez

  • Hero Member
  • *****
  • Posts: 537
    • PluriBASIC
Re: Corrupted executable generated.
« Reply #3 on: September 28, 2019, 09:25:52 AM »
For comparison sake, here is the correctly generated executable.

Brian Alvarez

  • Hero Member
  • *****
  • Posts: 537
    • PluriBASIC
Re: Corrupted executable generated.
« Reply #4 on: September 28, 2019, 09:44:01 AM »
Charles, i found version 0.2.7, tried to compile the faulty executable and it compiled and worked fine.

 Maybe this issue is fixed in newer versions?... i hope is not that just the alignment changed and it works
fine only in this instance.


Charles Pegge

  • Admin Support Member
  • *****
  • Posts: 4246
    • Oxygen Basic
Re: Corrupted executable generated.
« Reply #5 on: September 28, 2019, 10:43:42 AM »
Version 0.2.8 is the current OxygenBasicProgress.zip. The compiled binary is slightly smaller than in your first attachment but it executes ok, as far as I can tell.

Code: [Select]
...
PBMAIN() ' invoke entry point
mbox "ok"

Brian Alvarez

  • Hero Member
  • *****
  • Posts: 537
    • PluriBASIC
Re: Corrupted executable generated.
« Reply #6 on: September 29, 2019, 06:39:44 AM »
 This error occurs only at certain exact alignment... adding or removing statements fix it.
In this case, probably adding mbox "ok" fixed it.

 The updated version also have this error, but changing the RTL's changed the error alignment,
fixing this code for this version, but the bug still exists...

 For an example of it happening (and a chance to fix it), check the version 0.2.3 with the exact
code and resource i posted, this will probably give clues on how to fix it for newer versions.

Charles Pegge

  • Admin Support Member
  • *****
  • Posts: 4246
    • Oxygen Basic
Re: Corrupted executable generated.
« Reply #7 on: September 29, 2019, 02:21:15 PM »
Hi Brian,

It's not feasible to regress to 0.2.3 because there are about 50 changes. But if you get further exec failures with 0.2.8 then we will have something to work on. I've not had any so far.

Brian Alvarez

  • Hero Member
  • *****
  • Posts: 537
    • PluriBASIC
Re: Corrupted executable generated.
« Reply #8 on: September 29, 2019, 02:34:42 PM »
 Hello Charles, I completely understand that.

 But with this it will be pointless for others (beside you) to experience this issue.
Even if we report it, for when you have made changes to the code, it will probably be
always too late. What i can suggest is that when you release a new version, keep a separate
folder with the code to it, so that when i find the problem again, you can pull out the code
and look for the error. Finding a fix wont fix the newest version, but you will now know how
to apply a fix to the newest version... That said... i will report any errors with 0.2.8 if i get them,
hoping it is not too late. :)

 Also, Im not sure i explained myself correctly, when the engine generates a damaged
executable, it wont even be recognized by windows (see image attached or run the damaged executable),
so, adding a new statement to it (mbox "ok") will probably now generate a working executable, giving the false
illusion that there is no problem.

 I do understand there is no easy debugging for this one. As it is not easy to find it. I have found
this problem around 20 times. Every time it takes adding or removing a line of code to "fix it".

 I Usually just keep adding more lines of code until i no longer experience the issue. This works,
but i think at some point a real fix will be required?

Addendum:
 I experienced this problem in Windows 7, and it also happens in Windows 10.
« Last Edit: September 29, 2019, 02:47:34 PM by Brian Alvarez »

Charles Pegge

  • Admin Support Member
  • *****
  • Posts: 4246
    • Oxygen Basic
Re: Corrupted executable generated.
« Reply #9 on: September 29, 2019, 04:12:46 PM »
Yes understood. Such an error is hard to miss :)  I do see it occasionally, but it has always been due to a detectable and fixable bug.

I will shortly resume development on the graphics and audio projects of o2. These impose the greatest demands on language, complexity and size. These should help to expose any further hidden weaknesses.

Arnold

  • Hero Member
  • *****
  • Posts: 919
Re: Corrupted executable generated.
« Reply #10 on: September 29, 2019, 11:59:10 PM »
In a few cases I got the same error message like Brian. But it only happened when I ran a compiled 64-bit exe. As I am experimenting with 32-bit and 64-bit at the same time and also create errors in my code, I am not sure if there is a dependence. For instance I used ExitProcess in a code which created the error in 64-bit exe. Using version 0.2.8 and a fresh boot up, this error message does not appear at the moment after compiling.

Would it be helpful to report these occurences? It is perhaps a bit difficult sometimes to reproduce this error message. At the moment I think that this error only occurs in 64-bit mode.

« Last Edit: September 30, 2019, 01:21:39 AM by Arnold »

Charles Pegge

  • Admin Support Member
  • *****
  • Posts: 4246
    • Oxygen Basic
Re: Corrupted executable generated.
« Reply #11 on: October 01, 2019, 04:14:31 AM »
Yes, that would be very helpful, Roland. I am also lookin for ways of deliberately creating this error.

Brian Alvarez

  • Hero Member
  • *****
  • Posts: 537
    • PluriBASIC
Re: Corrupted executable generated.
« Reply #12 on: October 01, 2019, 03:24:13 PM »
 Thanks Charles, you are awesome. :)

Brian Alvarez

  • Hero Member
  • *****
  • Posts: 537
    • PluriBASIC
Re: Corrupted executable generated.
« Reply #13 on: December 04, 2019, 08:13:24 PM »
 Hello Charles, i have been a bit disconnected because of side obligations, but, are there news on this? :)

Charles Pegge

  • Admin Support Member
  • *****
  • Posts: 4246
    • Oxygen Basic
Re: Corrupted executable generated.
« Reply #14 on: December 07, 2019, 06:38:09 AM »
Hi Brian,

I have also been diverted over the last 2 months. We need some concise examples that can be analysed, and I don't have any of my own.

However, the next release (0.2.9) will fix a problem with quad function returns in 64bit mode.