Monday, January 5, 2009

Zune 30GB Offending Code Posted Online

The source code from the 30GB Microsoft Zune players that went haywire at the turn of the year was leaked online on pastie.org.

The section of code that causes an infinite loop is here:

while (days > 365)
{
if (IsLeapYear(year))
{
if (days > 366)
{
days -= 366;
year += 1;
}
}
else
{
days -= 365;
year += 1;
}
}

If the days counter reaches 366, we enter the while loop and you've either got a leap year or you've got to start incrementing the year. Now, when the year is a leap year, the code checks if the days counter is over 366. If the days counter is exactly 366, we don't do anything and return to the while condition. The while condition evaluates to true, so we're back in the loop, we check if the year is a leap year, the days over 366 'if' condition evaluates to false again, and we're stuck in an infinite loop.

No comments: