Oj::ParseError when parsing file upload in API::Files endpoint
Summary
An Oj::ParseError is occurring when attempting to parse JSON in the Files API endpoint, specifically when processing file uploads through the commits body uploader helper.
Error Details
Oj::ParseError: unexpected character 'v' [0x76] (after ) at line 3, column 28 [sparse.c:776] (Oj::ParseError)
from lib/api/helpers/commits_body_uploader_helper.rb:50:in `load_file'
from lib/api/helpers/commits_body_uploader_helper.rb:50:in `file_params_from_body_upload'
from lib/api/files.rb:338:in `block (2 levels) in <class:Files>'
Sentry Error: https://new-sentry.gitlab.net/organizations/gitlab/issues/2945265
Stack Trace Analysis
The error originates from:
-
lib/api/files.rb:338- Files API endpoint -
lib/api/helpers/commits_body_uploader_helper.rb:50-file_params_from_body_uploadmethod -
lib/api/helpers/commits_body_uploader_helper.rb:50-load_filemethod
The parser encounters an unexpected character 'v' (hex 0x76) at line 3, column 28, suggesting malformed JSON input.
Likely Cause
This issue is probably related to the changes made in #574324.
Potential Causes
- Invalid JSON format in the uploaded file body
- Encoding issues with the uploaded content
- Missing validation before JSON parsing
- Unexpected content type being processed as JSON
Impact
This error prevents users from successfully uploading files through the API when the request body contains malformed JSON.
Next Steps
-
Review the
load_filemethod inlib/api/helpers/commits_body_uploader_helper.rb - Add better error handling and validation before JSON parsing
- Check Sentry for frequency and patterns of this error
- Consider adding more descriptive error messages for users
Edited by Vasilii Iakliushin