- Feature Articles
- CodeSOD
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
If this is .NET, you forgot to mention the fact that the Bitmap and Image classes aren't actually supported in ASP.NET, also, for added fun and games
Admin
The original code also verifies that the image is actually an image before spaffing it over the intertubes to clients to whom we say it is an image.
Admittedly, it could do that without many of the in memory copies - which, although inefficient, are not that inefficient. I've seen a lot worse.
Admin
This jumble looks like it started from a misguided attempt to reuse code in ConvertImageToByteArray(). While not needed here, the procedure is necessary in .NET to use an image from a file without the un-intuitive file locking of disk-backed image memory.
Admin
This could so easily cause the problem which inspired the following ditty (to the tune of Love Story) ...
Where do I log in The URL has 404'ed on me again I've recompiled it using FORTRAN in CygWin I've even tried to stream the exe as a bin
Admin
Ahhh.. but arrays are reference objects....so perhaps not quite as many copies as you think....
(Still a WTF)
Admin
Minor point: It would need to be three lines. The 'replacement' code still doesn't set the content-disposition header.
There is sort of a decent point made about the code verifying that the file to serve really is an image (perhaps this is only a side-effect). BUT - given that it's hosted on the webserver, you'd hope that any such sanitisation was already performed at the time the file was created.
Admin
Yep.
Admin
How comes nobody realized that this code is not a WTF, it's enterprisey!!!
Admin
If you find yourself saying this, you've already introduced a flaw that can be corrupted later.
captcha: dolor - of course it's a color, nobody could have changed it after I sanitized the captcha
Admin
Hey... I saw this exact same WTF before in production code, except in Perl.
Admin
The explanation is incorrect. Some of the copying isn't actually copying: it's image conversion. The data that is sent has been through two lossy conversions with whatever the default quality parameters are.
Admin
The code is analogous to a junkie repeatedly stabbing their arm to find a vein, but they have all collapsed due to memory - er - drug abuse.
Admin
Well then the code must either be running on Bing Image search, or a porn site.
Admin
public void ResponseImageToBrowserFromXML(string xmlWithFileLocation) { ... } would be a quick fix, provided it uses:
ResponseImageFilePathExtractor pe = new ResponseImageFilePathExtractor(xmlWithFileLocation); string fileName = pw.getFilePath();
And of course the XML should come from a database.
Admin
Would make a nice insult: "The sum total of your knowledge could be steganographed into a favicon!!!".
Admin
Kudos to you for pointing out where this little gem can be improved :D
Admin
I've Seen Worse Guy
Admin
And what part of PERL was dealing in image processing?
Admin
Never heard of Image::Magick?
Admin
No this is part of IE. I am pretty sure about that. Just didn't know that Jack will send it to this site like he told he'll do.
Captcha: Appellatio: You know, Jack - you can always appellatio to an upper management when you'll get fired for breaking NDA. That will do nothing though.
The IE is crap and it will remain a crap until I live and work in this place. And even then my successor will keep it as crappy as possible. It's bad enough that it does follow standards now. It's harder and harder to make site that doesn't work in IE while working in sane browser. This isn't good. This isn't good.
Admin
The code is most likely old also it was probably copied from code that was using a PNG. I'm not sure if it still happens but if you attempted to write a PNG to the response directly in older version the code would crash, but if you wrote to a memory stream first the PNG would properly write out.
The real WTF is the .net image handling.
http://stackoverflow.com/questions/5629251/c-sharp-outputting-image-to-response-output-stream-giving-gdi-error
Admin
I hadn't. But despite my complete ignorance of the topic at hand, I felt the need to to insert some sort of smug comment to assuage my crushing lack of self-esteem. I'm an idiot, and I'll probably do it again in future.
Admin
And there's the real WTF… spelling it as PERL like it's an acronym. Hint: wrong.
Admin
Admin
Sorry Bruce, but while a given browser might forgive you for serving it a bitmap and calling it a jpeg, I won't on your code review. A bitmap is not a jpeg. The nice thing about the Image class (and its descendants such as Bitmap) in .NET is that it will allow you to save any supported image type to any other supported image type.
And whoever said that ASP.NET does not support the Bitmap and Image classes is full of pungent fertilizer.
Admin
Newb. The binary bitmap should be 64-bit encoded and then GZIPPED before storage into a BLOB column.
Admin
Admin
Posted to Facebook; soon to be someone's (:-) ) Slashdot sig
Admin
Yes they are, if you add a reference to System.Drawing
Admin
The code is only problematic if we can't guarantee filename will always point to a jpeg. More information needed.
Admin
Admin
My first thought was "nope, arrays of primitive types actually store their contents". But that's in Java, and this is .NET, which I don't know...
Someone please tell me .NET doesn't store this as references to some kind of "byte" object!
Admin
Also, the original code is not doing image conversion. The Bitmap constructor does not create any new data. If you save to the same format as the input, you will get an exact duplicate of the file, right down to the EXIF data. It doesn't re-encode anything unless the format actually changes.
Admin
Gosh, I've been away too long. When did [image] stop working?
Admin
Admin
Admin
Admin
Real world example (I spotted this while working for a Fortune 50 online brokerage):
image.pl?name=/charts/MYUSERID/asset_allocation.png
shows my current investment portfolio, while
image.pl?name=/charts/YOURUSERID/asset_allocation.png
reveals yours to anyone who asks nicely.
Admin
Uppercase tag/attribute, not closed, no alt attribute. Gross.
Also, you're assuming that the image itself is in a directory that is served.
Admin
Better?
So back to my original question. Did that stop working? Or do you overengineering weenies just feel the need to write new object oriented enterprisey code for things that already worked fine long ago?
Admin
To answer your question, yes, that stopped working. http://thedailywtf.com/Comments/Seeing-Sextuple.aspx#432153 http://thedailywtf.com/Comments/Seeing-Sextuple.aspx#432152
You're way off on just so much.
Admin
Not really... depending on (x)html version, case sensivity comes into play. Also you haven't (self) closed it.
Admin
Admin
Admin
HTML: forgiveness by default, but it's still sloppy.
Admin
Admin
Admin
it's LOOSE
Admin
obligatory XKCD for HTML standards: https://xkcd.com/927/
Admin
Well, I guess someone ought to tell Microsoft to update their documentation and remove the scare quote on the System.Drawing namespace: