Using StructLayout causes app to end - no CLR exception

  • Thread starter Richard A. Lowe
  • Start date
R

Richard A. Lowe

I've seen a number of people mention potential problems with the
StructLayoutAttribute possibly causing problems and it came up again in Ray
Z's post titled "covert between byte[] and int[]" just a bit earlier in this
newsgroup. So in trying some funky things with StructLayout and FieldOffset
to get a solution to that problem, I wrote some code that should never see
the light of day, but that nonetheless causes a total abnormal end in my
simple example (short, complete console app example posted to my blog here:
http://blogs.geekdojo.net/richard/posts/262.aspx )

What this code does is use two classes and the StructLayoutAttribute to
'unnaturally' manipulate a byte[] to become an int[]. However, after
several iterations of the loop (20 in my case) where it's doing the same
thing the program exits without an exception. Obviously this code is
contrived and not the correct way to marshal this data around. Still I'd
like to know if this is a problem security or framework-wise, or just a
"don't do that".

Thanks,
Richard
 
G

Grant Richins [MS]

Have you tried running on a network drive/share or some other untrusted
location? By default anything on your local machine is given full
permissions and can do anything at all (including unsafe and unverifiable
stuff like buffer overruns that crash the runtime).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top