Bad Code Contest
LINK ->->->-> https://urllie.com/2tEsyS
Unlike other programming contests, the goal of the OMGWTF contest is not to flex your algorithmic muscles and solve some abstract computational problem like you might in an ACM contest. Nor is it like the International Obfuscated C Coding Contest; in fact, writing code like that would be a surefire way to lose this contest. Instead, the goal of the OMGWTF contest is to solve an incredibly simple problem using the most obscenely convoluted way imaginable. And for this first contest, the simple problem is to build and implement the logic for a four-function calculator.
I asked some of my favorite bloggers to pick out the winning entries, and being the nice guys that they are, they agreed. The OMGWTF contest judges will be Raymond Chen, Joel Spolsky, and Jeremy Zawodny.
The contest is typically held in mid-November and heralded by the appearance of the distinctive Bad Poetry in Motion flyers around campus, which feature excerpts from memorable poems from throughout the contest's history. Many alumni of the Society also attend the event, which the Society treats as an unofficial gala, with current members often adopting an optional 'formal' dress code. There is no actual dress code however, and attendees are welcome in any manner of dress.
The Poetry Contest is dedicated to the memory of poet and Columbia alumnus (and one-time Philolexian vice president) Joyce Kilmer CC 1908. Best known for his work "Trees", Kilmer was unabashedly romantic and sentimental, and his poetry was disparaged by contemporary and later critics. However, "Trees" has endured in popularity, and served as the basis for innumerable parodies. Each year the contest ends with a reading of "Trees."
During an episode of the television show Castle, the title character's daughter, a Columbia student, informs him that she met her new boyfriend at "the annual bad poetry contest, right before Thanksgiving."[1]
Happiness and fun are linked to creative output. So coming up with absurd code examples like Luciano's is a way to set the stage and prepare your mind for creative work. It gets you into a creative mood.
There are examples like Luciano's that take a silly approach to solving a simple problem. Then there's the Obfuscated C Mandelbrot- and Julia-set Generator. It's written in ANSI-C and its source code resembles the Mandelbrot set:
The absurdity might lie in the silliness of the problem's solutions. Or it might be found in the presentation of the code itself. Sometimes, it's about writing innocuous-looking code with a sinister secret.
The International Imitation Hemingway Competition, also known as the Bad Hemingway Contest, was an annual writing competition begun in Century City, California. Started in 1977 as a "promotional gag",[1] and held for nearly thirty years, the contest pays mock homage to Ernest Hemingway by encouraging authors to submit a 'really good page of really bad Hemingway' in a Hemingway-esque style.[2]
In addition to the humor of the contest, there is irony in its existence, as Hemingway famously said: "The step up from writing parodies is writing on the wall above the urinal." Nevertheless, the contest had thousands of dedicated enthusiasts among writers and Hemingway fans, drawing more than 24,000 entries in its first ten years of operation.[7] Many notable literary figures judged the contest over the years, including Digby Diehl, Jack Smith, Ray Bradbury, Barnaby Conrad, George Plimpton, Bernice Kert,[2] Jack Hemingway, A. Scott Berg, and Joseph Wambaugh.[8][9]
In the late 1970s, seeking to promote Harry's Bar & American Grill in Century City, California, bar owners Jerry Magnin and Larry Mindel consulted advertising executive Paul Keye, who suggested the contest to capitalize on Hemingway's literary references to "Harry's".[10] The contest announcement in The New Yorker magazine stated, "One very good page of very bad Hemingway will send you and a friend to Italy for dinner."[6] For the 11th Annual Contest, to promote the contest's move from (closing) Century City to the San Francisco Harry's, PR firm Tellem Worldwide recruited noted San Francisco authors Herb Caen, Lawrence Ferlinghetti and Cyra McFadden as judges.[7]
In 1988, after 11 years of contests, Spectrum Foods Inc., the new owners of Harry's in Los Angeles, ended their sponsorship of the contest because of escalating costs.[11] At this time literary organization PEN Center West took over sponsorship.[12] American Airlines' in-flight magazine American Way began printing contest-winning entries, and continued the grand prize of a flight to Italy.[1] In 2000 United Airlines assumed sponsorship of the contest, publishing winning entries in their in-flight and online Hemispheres Magazine.[13] United Airlines' support continued until the 2005 contest,[14] following which the competition ended.[15] The final winning parody was entitled "Da Movable Code."[16]
Hemingway's spare writing style had often been imitated prior to the contest. Since then, two anthologies of Imitation Hemingway have been published (The Best of Bad Hemingway, Volumes I & II) and include contest winners as well as satires of Hemingway written by E. B. White, Raymond Chandler, F. Scott Fitzgerald and George Plimpton.[17][18]
Finally, we are going to run a live Reddit AMA ("Ask Me Anything," for those of you who, like me, still use a tape recorder and a Commodore PET CBM) next Tuesday, February 9th, at 1:00pm. We'll post more specifics later, but if you have questions about Underhanded C, the contest or the problem, this will be a great opportunity to ask.
One problem with NaN poisoning is that many coders are cautious about dividing by zero; to a C programmer, looking at a floating-point division without a zero-check is a bit like watching a toddler playing with a steak knife. Such oversights are likely to draw attention on review. Some submitters addressed this by introducing zero-checks that didn't work, to wit this entry by Michael Dunphy:
A few other interesting NaN tricks included a fun entry by Sean Egan, which combined a straightforward match() function with the following main() code to parse test[] and reference[] values from a text file input:
The arrays are memset() to 0xFF, and then loaded with numbers from the file. If the file contains an entry that is not parseable as a number, which can happen by a lot of tricks such as funny Unicode characters that resemble digits, sscanf() will leave that array element unassigned, and a double variable made out of 0xFF values is a NaN.
Because of little-endian representation, overwriting the first two bytes of the exponent changes it to a value that is just a tiny bit more than 2.0 -- subtle enough that it will still display as 2.0 when the logging code prints it out! But since it is not an integer, pow( o[i]-e[i], glob.diff_exp) returns NaN whenever the first argument is negative.
This one computes the Euclidean distance between the test[] and reference[] arrays, with an extra quirk of removing the largest outlier distance from the sum. I don't quote it here, but this also includes validation code to flag infinite values.
The bug is that the error handler is called error_messager, and the code instead passes error_message, which is a string. The code mistakenly calls a string as a function, which would normally cause crashy things to happen--except the initial bytes of the Unicode string are valid x86 instructions, that pop a stack frame and causes do_elements_match to return true.
This bug is perceptual in nature: several functions in this code follow a goto pattern of goto done;error: result = 0;done: return result;...but in this function the { goto done; } is inside a curly brace. A newly allocated pool entry will fall through to error: and return a 0 to sample_create(), which then fails to initialize the new node with the array data. In those nodes, the entries test, reference and threshold are all 0, and they always match as samples.
This is a straightforward but very clever negative-number bug. The code computes the area of peaks in the spectra and compares them, but a bug causes the test[] array values to be negated. Nobody expects the spectrum values to be negative, or expects that the area under a peak would therefore be negative. This causes the following code to always pass:
A main function expects a spectrum with two extra numbers showing the starting and ending time of a scan. It then normalizes the spectrum from counts to counts/sec, by computing the time differential and dividing by it (in the bolded lines of the code above).
Beyond that type confusion, the code does nothing unusual or suspicious or quirky or different: it is a bog-standard implementation of preprocessing followed by normalized correlation. There is really nothing underhanded in the rest of the code! Here is the comparison code (which is called after the program verifies that the spectrum has sufficient energy, so there is no division by zero error):
Why did we like this one? The attack is realistically achievable without triggering some effect in the computer, like tampering with a system clock or a file permission;It uses a real-world approach to comparing spectra, rather than something simple or contrived;If you miss the type confusion, there is nothing at all about the remaining code that looks the slightest bitsuspicious or unusual; It gets down to the bitwise representation of floating-point numbers, and causing a confusion of datatypes with usable results is ingenious; It exploits the fact that the doubles hold whole number counts, which allows the miscasting of doubles to work; The attack is actually transparent to all the filtering and preprocessing, which preserves the whole-number property of the data;Despite all this, it's still only 60-odd lines of code, that looks incredibly innocent.Congratulations Linus Åkesson, you are the most underhanded C programmer of 2015. 781b155fdc