Thursday, April 16, 2015

Encountered a bug where if a user uploads a photo, and then rotates the photo, and then rotates the photo again, the second rotation produces an error, but only if the user is not logged in.  After looking into this for a bit, I discovered that the rotation code checked if the photo was associated with a user, and if it was, it tried to access the user's info.  But if the user was not logged in, the code would produce an error.  The part that baffled me was why the photo was associated with a user when the user was not logged in.

After spending the better part of a day investigating this, I pieced together the workflow of the photo process:

1) Non-logged-in user uploads a photo.  The photo's info is saved to memory with no user associated with it.  The photo's info is then saved to the database.  However, for whatever reason, the database requires that a photo has an associated user, so a fake user is stored.

2) User rotates the photo.  The photo's info is retrieved from memory, which has no user associated with it.  Then the actual rotation occurs, and stuff is written to the database.  The photo's info is then retrieved from the database and written back to memory.  However, since the database has a fake user associated with the photo, that fake user is written to memory.

3) User rotates the photo again.  The photo's info is retrieved from memory, but this time, the photo is associated with a fake user.  Then the actual rotation occurs, but since this time the photo is associated with a fake user, the code tries to access the user's info, and since the user is not logged in, the code blows up.