News for hackers. Stuff that matters.
Re:Students are failing AP tests because the College Board c... by snazz on Thursday May 21, 2020 @01:28PM (#23261598)
Here's the relevant frontend source code for the file upload picker, if anyone's wondering (webpack://src/components/exam/submissions/FileInput.js):

  <input
            type="file"
            ref={inputRef}
            name="fileupload"
            disabled={disabled}
            accept={EXTENSIONS[type]}
            data-cb-element="no-cb"
            onChange={async e => {
              const [file] = Object.keys(e.target.files).map(key => e.target.files[key])
              const fileSizeInMb = file.size/(CONVERSION_BASE*CONVERSION_BASE)
              const fileSizeInKb = file.size/CONVERSION_BASE
              const split = file.name.split('.')
              const fileType = split[split.length-1].toLowerCase()
              const extensions = EXTENSIONS[type].split(', ')
              const isAllowedExtension = extensions.includes(`.${fileType}`)
              const alreadyExists = files.find(f => f.name === file.name && f.size === file.size && f.lastModified === file.lastModified)
              let error

              if (alreadyExists)
                error = { title: 'You have already uploaded a file with the same name.', details: 'Please attach a different file.' }
              else if (!isAllowedExtension)
                error = { title: 'This file type is not acceptable.', details: 'Please check the requirements, save your file in one of the accepted formats, and resubmit.' }
              else if (fileSizeInKb <= minSize)
                error = { title: 'Your file is too small.', details: 'Please check the file-size requirements, save a larger version, and resubmit.' }
              else if (fileSizeInMb > maxSize)
                error = { title: 'Your file is too big.', details: 'Please check the file-size requirements, save a smaller version, and resubmit. ' }
            
              if (error)
                await setError(<><strong>{error.title}</strong> {error.details}</>)
              else {
                await updateFiles(file)
                setError(null)
              }

              inputRef.current.value = null
            }}
          />
The EXTENSIONS variable is defined here:

  export const EXTENSIONS = {
    [TYPE_DOC]: '.txt, .doc, .docx, .pdf, .odt',
    [TYPE_PHOTO]: '.png, .jpg, .jpeg',
    [TYPE_AUDIO]: '.m4a, .mp3, .wav, .ogg'
  }
Re:Students are failing AP tests because the College Board c... by machello13 on Thursday May 21, 2020 @01:52PM (#23262022)
So do we know yet why iOS wasn't auto-converting the HEIC images? Is it because they didn't use mime types in the `accept` attribute?
Re:Students are failing AP tests because the College Board c... by 43920 on Thursday May 21, 2020 @02:31PM (#23262776)
A lot of the people with issues appear to have airdropped the photo to their computer (which doesn't trigger the auto-conversion path), and then uploaded it from there (possibly using a non-Safari browser, which wouldn't do any conversion).
Re:Students are failing AP tests because the College Board c... by snazz on Thursday May 21, 2020 @02:07PM (#23262354)
That's my guess, looking at how they made the accept attribute.
Re:Students are failing AP tests because the College Board c... by scott_s on Thursday May 21, 2020 @02:13PM (#23262456)
I wondered that, too, but when I googled around for how to do that properly, I didn't see anything saying it matters.
Re:Students are failing AP tests because the College Board c... by tiglionabbit on Thursday May 21, 2020 @03:07PM (#23263420)
Huh. So, according to the other comments, if they'd set the `accepts` on their form to MIME types instead of extensions, the browser would have converted the file to a JPG automatically.
Re:Students are failing AP tests because the College Board c... by KingMachiavelli on Thursday May 21, 2020 @03:57PM (#23264199)
Which means I think the blame is more on Apple side since the 'accept' attribute is intended to work with any 'Unique file type specifiers' [1] which includes both MIME types and extensions. Perhaps Apple is following a different RFC?

[1] https://developer.mozilla.org/en-US/docs/Web/HTML/Element/in...

Re:Students are failing AP tests because the College Board c... by savrajsingh on Thursday May 21, 2020 @06:44PM (#23266424)
Haha, the fact that we are code reviewing this on HN is amazing. OK, the issue is "accept" isn't formatted as "image/jpeg, image/png", it's a list of file extensions. Which apparently wasn't enough to trigger iPhone's auto-conversion, and they just decided there wasn't a tech fix. You can totally see why -- they just never tried the mime-types.
Re:Students are failing AP tests because the College Board c... by scott_s on Thursday May 21, 2020 @01:54PM (#23262067)
I'm trying to square this with the fact people pointed out downthread, which is that iPhones will automatically convert HEIC images to jpeg from an HTML input form. Perhaps it's the `isAllowedExtension` check? If `e.target.files` is the actual file names on disk (and not whatever temporary file the browser made out of the HEIC file), that would cause a problem.
Re:Students are failing AP tests because the College Board c... by acqq on Thursday May 21, 2020 @02:11PM (#23262429)
Apparently somebody claims to have been able to change the extension and submit the picture, but got "file corrupted" later:

"Senior Dave Spencer took a demo test before his Calculus AB exam to make sure he understood the process for uploading photos. He Airdropped an iPhone image of his responses to his Mac and tried to convert it by renaming the HEIC file to PNG. Changing a file’s extension does not guarantee that it will be converted, but Spencer was still able to submit the demo test with no problem.

Spencer used the same process on the real exam and thought it went through, but he received an email the next day saying the files were corrupted and that he needed to retake the test."

Re:Students are failing AP tests because the College Board c... by hysan on Thursday May 21, 2020 @03:48PM (#23264041)
As someone who started their career in QA and volunteered with IT support for non-technical organizations, this is one of the first test cases I would have thought to try.

Never trust user input!

Frontend validation can never be trusted. It’s only good for giving faster feedback for a nicer user experience. You should always have backend validation.

I’ve seen people do some weird stuff before because the majority of users don’t really understand much about file types. Users rename file extension all of the time thinking it’ll magically convert a file into something that can be opened by their program of choice.

This is just poor QA by the College Board.

Re:Students are failing AP tests because the College Board c... by Spivak on Thursday May 21, 2020 @02:30PM (#23262762)
Anyone who says that young people are better with computers these days needs to keep this paragraph on file.

I can’t really blame the college board for this kind of mistake. Like would he assume that taking a .docx and renaming it to .pdf converts it?

Re:Students are failing AP tests because the College Board c... by 7786655 on Thursday May 21, 2020 @02:51PM (#23263143)
On the other hand, I think there's an argument to be made software should ignore file extensions whenever possible. Is really that hard for the backend to check if the file starts with "\xFF\xD8\xFF\xE0\0\x10JFIF\0\1" or "\x89PNG\r\n\x1A\n"? That would have caught this problem.
Re:Students are failing AP tests because the College Board c... by stefan_ on Thursday May 21, 2020 @05:01PM (#23265263)
Yes, just hardcode what is hopefully the magic bytes for the formats we expect, what could possibly go wrong /s

The biggest joke here is that this wouldn't have helped the students either. I don't think any of them will pass the "there is a minute left on the timer and the website tells you your picture isn't JPEG or PNG" challenge.

Re:Students are failing AP tests because the College Board c... by 7786655 on Thursday May 21, 2020 @05:28PM (#23265620)
I did some more research and it looks like I got the one for JPEG wrong, so maybe you have a point.
Re:Students are failing AP tests because the College Board c... by scott_s on Thursday May 21, 2020 @02:20PM (#23262587)
That anecdote is inline with my explanation: the student manually changed the file extension on disk, then uploaded that. That would pass all of the checks, but it would still be in the wrong format, as manually changing the file extension does not cause a conversion to take place on disk, and that probably prevents the automatic conversion of HEIC to jpeg the iPhone itself does on such input fields.
Re:Students are failing AP tests because the College Board c... by xxs on Thursday May 21, 2020 @04:48PM (#23265020)
all the checks - a proper check would be reading the contents and parsing the image.
Re:Students are failing AP tests because the College Board c... by scott_s on Friday May 22, 2020 @09:30AM (#23271813)
Yes, but that's not what the written code does.
Re:Students are failing AP tests because the College Board c... by hamandcheese on Thursday May 21, 2020 @03:15PM (#23263533)
I think the issue is that accept is specified only with extensions rather than mime types.
Re:Students are failing AP tests because the College Board c... by scott_s on Thursday May 21, 2020 @03:53PM (#23264126)
I wondered that, too, but I couldn't find any HTML documentation that blessed one form as superior to the other. And I would be surprised if Apple automatically converted images for "accept=image/jpg" but not "accept=.jpg".
Re:Students are failing AP tests because the College Board c... by johnp_ on Thursday May 21, 2020 @04:58PM (#23265222)
Here's the spec:

https://html.spec.whatwg.org/multipage/input.html#attr-input...

> Authors are encouraged to specify both any MIME types and any corresponding extensions when looking for data in a specific format.

> User agents should prevent the user from selecting files that are not accepted by one (or more) of these tokens.