The Console That Thought 2010 Was a Leap Year — Bug Hunt
Modelled on ApocalyPS3 (1 March 2010): the PlayStation 3's clock firmware treated 2010 as a leap year.
- Language: JavaScript
- Layer: Backend
- Difficulty: Medium
- Concepts: Dates, Leap Years
- Modelled on: PlayStation 3 · 2010
- Visible tests: ordinary leap years are leap; 2010 is not a leap year
- Reward: 50 XP for a complete fix
Incident
- Severity: SEV-1 (priority: Critical)
- Ticket: BUG-8001050F
- Reported by: platform
- Time to fix: 20 minutes, the target for a medium incident
Failing checks on the shipped build
- 2010 is not a leap year — 2010 is not divisible by 4: expected false but got true
How to work this incident
- Read the report: write down the expected behaviour and the actual one in a sentence each.
- Reproduce it: run the visible tests and find the failing check that matches the report.
- Read the logs and the failing checks for the first value that is wrong — the earliest wrong value is nearer the cause than the loudest error.
- Follow the request through the handler, the validation and the service it calls; find the first step whose output disagrees with the report.
- Fix the cause rather than the symptom, run the visible tests again, and submit against the hidden ones — then write the root cause down.
Briefing
Modelled on ApocalyPS3 (1 March 2010): the PlayStation 3's clock firmware treated 2010 as a leap year. On 1 March the hardware reported a 29 February that did not exist, date validation failed everywhere, and older consoles worldwide could not sign in, play games or use trophies.
clock.js has the same faulty leap-year rule.
Fix isLeapYear so it follows the Gregorian rule.
Bug report
BUG-8001050F · Priority: Critical · Reported by: platform
isLeapYear(year) must implement the Gregorian rule:
- divisible by 4 -> leap
- unless divisible by 100 -> not leap
- unless divisible by 400 -> leap
Observed: 2010 is reported as a leap year, and so is every year ending in 0. 1900 is also wrong in the other direction.
Logs
[rtc] date rolled to 2010-02-29
[rtc] trophy sync failed: invalid timestampThe code as shipped
src/clock/clock.js (editable)
// Gregorian leap-year test.
exports.isLeapYear = function (year) {
// "Every fourth year, and also the round ones" — as shipped.
if (year % 10 === 0) return true;
return year % 4 === 0;
};
exports.daysInFebruary = function (year) {
return exports.isLeapYear(year) ? 29 : 28;
};
Open the hunt to start the incident clock, edit the files, run the visible tests and submit against the hidden ones, then write the root cause down. More JavaScript bug hunts.