[VM] Build report and queries (Unix and Win32)

Lex Spoon lex at cc.gatech.edu
Wed Feb 20 22:32:24 UTC 2002


On Wed, Feb 20, 2002 at 02:35:37PM -0500, David Pennell wrote:
> 
> > 1.  What's up with the 512 byte header on Unix?  The code I 
> > wrote to deal 
> > with it was in routines that did checking, but not the main 
> > routine that 
> > actually reads and understands the image.  This makes me a bit 
> > nervous.  The main code looks as if it automatically seeks 512 bytes 
> > forward if it runs into trouble, and I guess the file is read 
> > from this 
> > offset.  Is that really all there is to it?  Obviously a 
> > messup on this 
> > could be catastrophic.

That's all there is to it.  Magic numbers for file types are
theoretically, they are unsound, but in practice work wonderfully.  For
example, magic numbers appear to be more reliable than resource forks
on Mac's, even though resource forks are much sounder in theory:  in
practice, it's not too hard to accidentally download an image the wrong way
and thus end up with the wrong file type.

Anyway, Bad Catastraphic Horrible Bad Things aren't real likely: you'd
have to specify an incorrect image file, and furthermore the file:

    - would have to have the right 2-byte magic number in one of two places

    - would have to be close enough to a valid image file that loading works

    - would actually have to have enough valid Squeak bytecodes to do
    something bad, catastrophic, horrible, or bad instead of just
    immediately crashing

I've never seen it happen, either with Squeak, or with Unix
in its wide use of magic numbers on files.  It's rare to get
to the last criterion above, and then everything I've seen just
crashes.


> > 
> > The unix code redefines sqImageFileStartLocation and claims this is 
> > automatically used.  But the only caller I found (in 
> > interp.c) uses it when 
> > writing, not reading.  This is just as well, since it's hard 
> > coded to 512, 
> > while on Unix some files have the extra header and some 
> > don't.  All this 
> > left me with an uneasy feeling.


Take a look at checkImageVersionFrom:startingAt: -- this will automatically
seek into the file 512 bytes if it finds a magic number there.

It's kind of interesting how different platforms are affected by this.
Old Unix VM's are perfectly fine with these images, because they just
obediently pass on the requested image file to the platform-independent
portion of Squeak.  The Windows VM's (and maybe the Mac VM's?) try to
do some sanity checking to protect the user from Bad Catastrophic
Horrible Bad Things that they couldn't possibly want, and end up
being a tiny bit too restrictive.  Instead of fixing the sanity check,
it would be possible to just *remove* the check, but I don't remember
anyone proposing that kind of solution.  Likewise, no one has proposed
*adding* such a sanity check to the Unix VM....



-Lex



More information about the Squeak-dev mailing list