Exploit using files in HW4 (to get extremely low efficiency)

gianluca5539 (9710 points)
2 4 42
asked Nov 12, 2021 in HW4 by gianluca5539 (9,710 points)
Yesterday I noticed that you can score a very very good efficiency, as little as 30ms, by exploiting a "bug" in the VM test system.

This is what i think happens:

Since the tests are repeated, you can make the code execute almost instantly in all test rounds after the first by opening the files with mode 'x', exclusive creating mode.

As the files already exist after the first test, the exclusive creating mode will throw an error saying that the file already exists. This will take an extremely small amount of time and so the total execution time will be very small. The result is then all tests passed in ~35ms.

This is obviously not a fair way to solve the homework.

The "fix" is easy: just use the 'w' mode, which will create the files if they don't exist or overwrite them if they exist.

I'm writing this so that, if you find a very small execution time, you know that you are actually (probably without even noticing) exploiting a bug.

Wish everyone good luck with HW4!
227 views

3 Answers

andrea.sterbini (167380 points)
487 897 1724
answered Nov 12, 2021 by andrea.sterbini (167,380 points)
edited Nov 12, 2021 by andrea.sterbini
Thanks for signaling this, I've added an "file open mode check" to the VM tests
andrea.sterbini (167380 points)
487 897 1724
commented Nov 15, 2021 by andrea.sterbini (167,380 points)
Found an even easier solution: delete the output file after the test
James_F (4380 points)
6 12 33
answered Nov 12, 2021 by James_F (4,380 points)
Brilliant catch!
Quellocinese (2670 points)
2 3 22
answered Nov 12, 2021 by Quellocinese (2,670 points)
This is brilliant.