diff options
| author | Douwe Maan <douwe@gitlab.com> | 2016-08-15 15:27:41 +0000 |
|---|---|---|
| committer | Douwe Maan <douwe@gitlab.com> | 2016-08-15 15:27:41 +0000 |
| commit | 9aa68b877fe2feda7110703f591dc60622422010 (patch) | |
| tree | 5dba10b0d9c6ab557fc3f457b9e45099c0b10e67 /app/models | |
| parent | 6af598fc173bd0f7cd4237fa3e60d223103301a3 (diff) | |
| parent | 8171544b3d44df6ce810aa436bf87d137bc9b28f (diff) | |
| download | gitlab-ce-9aa68b877fe2feda7110703f591dc60622422010.tar.gz | |
Merge branch 'svg-render-size-limit' into 'master'
Limit the size of SVGs when viewing them as blobs
## What does this MR do?
This MR prevents rendering of SVG blobs larger than 2 MB.
## Are there points in the code the reviewer needs to double check?
I couldn't figure out how to properly test the view for this as this requires a large SVG (inflating the repository size) _or_ stubbing, the latter doesn't really seem possible using Spinach and all the stuff potentially involved.
## Why was this MR needed?
When rendering large SVG blobs (e.g. 20 MB files) a request may time out and consume a lot of memory.
## What are the relevant issue numbers?
#1435
## Screenshots (if relevant)

## Does this MR meet the acceptance criteria?
- [x] [CHANGELOG](https://gitlab.com/gitlab-org/gitlab-ce/blob/master/CHANGELOG) entry added
- [x] ~~[Documentation created/updated](https://gitlab.com/gitlab-org/gitlab-ce/blob/master/doc/development/doc_styleguide.md)~~
- [x] ~~API support added~~
- Tests
- [x] Added for this feature/bug
- [ ] All builds are passing
- [ ] Conform by the [style guides](https://gitlab.com/gitlab-org/gitlab-ce/blob/master/CONTRIBUTING.md#style-guides)
- [ ] Branch has no merge conflicts with `master` (if you do - rebase it please)
- [x] [Squashed related commits together](https://git-scm.com/book/en/Git-Tools-Rewriting-History#Squashing-Commits)
cc @jschatz1 @annabeldunstone (there are some UI changes, see the above screenshot).
See merge request !5794
Diffstat (limited to 'app/models')
| -rw-r--r-- | app/models/blob.rb | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/app/models/blob.rb b/app/models/blob.rb index 0df2805e448..12cc5aaafba 100644 --- a/app/models/blob.rb +++ b/app/models/blob.rb @@ -3,6 +3,9 @@ class Blob < SimpleDelegator CACHE_TIME = 60 # Cache raw blobs referred to by a (mutable) ref for 1 minute CACHE_TIME_IMMUTABLE = 3600 # Cache blobs referred to by an immutable reference for 1 hour + # The maximum size of an SVG that can be displayed. + MAXIMUM_SVG_SIZE = 2.megabytes + # Wrap a Gitlab::Git::Blob object, or return nil when given nil # # This method prevents the decorated object from evaluating to "truthy" when @@ -31,6 +34,10 @@ class Blob < SimpleDelegator text? && language && language.name == 'SVG' end + def size_within_svg_limits? + size <= MAXIMUM_SVG_SIZE + end + def video? UploaderHelper::VIDEO_EXT.include?(extname.downcase.delete('.')) end |
