HTTP/2 200
date: Sat, 19 Jul 2025 21:40:59 GMT
content-type: text/html; charset=utf-8
vary: X-PJAX, X-PJAX-Container, Turbo-Visit, Turbo-Frame, X-Requested-With,Accept-Encoding, Accept, X-Requested-With
x-repository-download: git clone https://github.com/pedrocr/rawloader.git
etag: W/"385058239c367d11d729c1a8d32d2e5e"
cache-control: max-age=0, private, must-revalidate
strict-transport-security: max-age=31536000; includeSubdomains; preload
x-frame-options: deny
x-content-type-options: nosniff
x-xss-protection: 0
referrer-policy: no-referrer-when-downgrade
content-security-policy: default-src 'none'; base-uri 'self'; child-src github.githubassets.com github.com/assets-cdn/worker/ github.com/assets/ gist.github.com/assets-cdn/worker/; connect-src 'self' uploads.github.com www.githubstatus.com collector.github.com raw.githubusercontent.com api.github.com github-cloud.s3.amazonaws.com github-production-repository-file-5c1aeb.s3.amazonaws.com github-production-upload-manifest-file-7fdce7.s3.amazonaws.com github-production-user-asset-6210df.s3.amazonaws.com *.rel.tunnels.api.visualstudio.com wss://*.rel.tunnels.api.visualstudio.com objects-origin.githubusercontent.com copilot-proxy.githubusercontent.com proxy.individual.githubcopilot.com proxy.business.githubcopilot.com proxy.enterprise.githubcopilot.com *.actions.githubusercontent.com wss://*.actions.githubusercontent.com productionresultssa0.blob.core.windows.net/ productionresultssa1.blob.core.windows.net/ productionresultssa2.blob.core.windows.net/ productionresultssa3.blob.core.windows.net/ productionresultssa4.blob.core.windows.net/ productionresultssa5.blob.core.windows.net/ productionresultssa6.blob.core.windows.net/ productionresultssa7.blob.core.windows.net/ productionresultssa8.blob.core.windows.net/ productionresultssa9.blob.core.windows.net/ productionresultssa10.blob.core.windows.net/ productionresultssa11.blob.core.windows.net/ productionresultssa12.blob.core.windows.net/ productionresultssa13.blob.core.windows.net/ productionresultssa14.blob.core.windows.net/ productionresultssa15.blob.core.windows.net/ productionresultssa16.blob.core.windows.net/ productionresultssa17.blob.core.windows.net/ productionresultssa18.blob.core.windows.net/ productionresultssa19.blob.core.windows.net/ github-production-repository-image-32fea6.s3.amazonaws.com github-production-release-asset-2e65be.s3.amazonaws.com insights.github.com wss://alive.github.com api.githubcopilot.com api.individual.githubcopilot.com api.business.githubcopilot.com api.enterprise.githubcopilot.com; font-src github.githubassets.com; form-action 'self' github.com gist.github.com copilot-workspace.githubnext.com objects-origin.githubusercontent.com; frame-ancestors 'none'; frame-src viewscreen.githubusercontent.com notebooks.githubusercontent.com; img-src 'self' data: blob: github.githubassets.com media.githubusercontent.com camo.githubusercontent.com identicons.github.com avatars.githubusercontent.com private-avatars.githubusercontent.com github-cloud.s3.amazonaws.com objects.githubusercontent.com release-assets.githubusercontent.com secured-user-images.githubusercontent.com/ user-images.githubusercontent.com/ private-user-images.githubusercontent.com opengraph.githubassets.com copilotprodattachments.blob.core.windows.net/github-production-copilot-attachments/ github-production-user-asset-6210df.s3.amazonaws.com customer-stories-feed.github.com spotlights-feed.github.com objects-origin.githubusercontent.com *.githubusercontent.com; manifest-src 'self'; media-src github.com user-images.githubusercontent.com/ secured-user-images.githubusercontent.com/ private-user-images.githubusercontent.com github-production-user-asset-6210df.s3.amazonaws.com gist.github.com; script-src github.githubassets.com; style-src 'unsafe-inline' github.githubassets.com; upgrade-insecure-requests; worker-src github.githubassets.com github.com/assets-cdn/worker/ github.com/assets/ gist.github.com/assets-cdn/worker/
server: github.com
content-encoding: gzip
accept-ranges: bytes
set-cookie: _gh_sess=hEVorpYdJ9mpdg95bf3VpyA2K2%2FcGsR%2FyuCJ3zi2kvCIYi16jpcWNRfI8mcK6nv%2Fzxes6lamAmBpkXF8c0xIQn%2B%2BwpYNEYLbJpcJF%2BO892ME4VXifE0nlkSZUJRip5aKEkciK1n1Jvlu5%2B0L5y6LysGzYBsEjQeBmdSXfIjnR74eB8LtDRD7jJrvFiEkpp8lPVOmit9%2FvpkYOFV%2FrCEjqi23Oa%2BMxk3tEs4F87%2BIYHYO13gQJ4wkdfsq3nx6KvYFMOvc4QbxHns36%2BjI1mnppg%3D%3D--zwEMk5mNtK73GQow--DQ9nQgSeP8Inlnp58CoyxQ%3D%3D; Path=/; HttpOnly; Secure; SameSite=Lax
set-cookie: _octo=GH1.1.2003831830.1752961258; Path=/; Domain=github.com; Expires=Sun, 19 Jul 2026 21:40:58 GMT; Secure; SameSite=Lax
set-cookie: logged_in=no; Path=/; Domain=github.com; Expires=Sun, 19 Jul 2026 21:40:58 GMT; HttpOnly; Secure; SameSite=Lax
x-github-request-id: A964:110E0E:863BFA:AA7705:687C10EA
Prevent huge memory allocations from bad data · pedrocr/rawloader@aaf584b · GitHub
File tree Expand file tree Collapse file tree 16 files changed +33
-21
lines changed Expand file tree Collapse file tree 16 files changed +33
-21
lines changed Original file line number Diff line number Diff line change @@ -141,7 +141,7 @@ impl<'a> ArwDecoder<'a> {
141
141
142
142
fn decode_arw1 ( buf : & [ u8 ] , width : usize , height : usize ) -> Vec < u16 > {
143
143
let mut pump = BitPumpMSB :: new ( buf) ;
144
- let mut out: Vec < u16 > = vec ! [ 0 ; width* height] ;
144
+ let mut out: Vec < u16 > = alloc_image ! ( width, height) ;
145
145
146
146
let mut sum: i32 = 0 ;
147
147
for x in 0 ..width {
Original file line number Diff line number Diff line change @@ -83,7 +83,7 @@ pub static LITTLE_ENDIAN: Endian = Endian{big: false};
83
83
pub fn decode_threaded < F > ( width : usize , height : usize , closure : & F ) -> Vec < u16 >
84
84
where F : Fn ( & mut [ u16 ] , usize ) +Sync {
85
85
86
- let mut out: Vec < u16 > = vec ! [ 0 ; width* height] ;
86
+ let mut out: Vec < u16 > = alloc_image ! ( width, height) ;
87
87
out. par_chunks_mut ( width) . enumerate ( ) . for_each ( |( row, line) | {
88
88
closure ( line, row) ;
89
89
} ) ;
@@ -93,7 +93,7 @@ pub fn decode_threaded<F>(width: usize, height: usize, closure: &F) -> Vec<u16>
93
93
pub fn decode_threaded_multiline < F > ( width : usize , height : usize , lines : usize , closure : & F ) -> Vec < u16 >
94
94
where F : Fn ( & mut [ u16 ] , usize ) +Sync {
95
95
96
- let mut out: Vec < u16 > = vec ! [ 0 ; width* height] ;
96
+ let mut out: Vec < u16 > = alloc_image ! ( width, height) ;
97
97
out. par_chunks_mut ( width* lines) . enumerate ( ) . for_each ( |( row, line) | {
98
98
closure ( line, row* lines) ;
99
99
} ) ;
Original file line number Diff line number Diff line change @@ -44,7 +44,7 @@ impl<'a> Decoder for Cr2Decoder<'a> {
44
44
let mut width = ljpegwidth;
45
45
let mut height = decompressor. height ( ) ;
46
46
let cpp = if decompressor. super_h ( ) == 2 { 3 } else { 1 } ;
47
- let mut ljpegout = vec ! [ 0 as u16 ; width* height] ;
47
+ let mut ljpegout = alloc_image ! ( width, height) ;
48
48
try!( decompressor. decode ( & mut ljpegout, 0 , width, width, height) ) ;
49
49
50
50
// Linearize the output (applies only to D2000 as far as I can tell)
@@ -87,7 +87,7 @@ impl<'a> Decoder for Cr2Decoder<'a> {
87
87
if canoncol. get_usize ( 0 ) == 0 {
88
88
( width, height, cpp, ljpegout)
89
89
} else {
90
- let mut out = vec ! [ 0 as u16 ; width* height] ;
90
+ let mut out = alloc_image ! ( width, height) ;
91
91
let mut fieldwidths = Vec :: new ( ) ;
92
92
for _ in 0 ..canoncol. get_usize ( 0 ) {
93
93
fieldwidths. push ( canoncol. get_usize ( 1 ) ) ;
Original file line number Diff line number Diff line change @@ -189,7 +189,7 @@ impl<'a> CrwDecoder<'a> {
189
189
}
190
190
191
191
fn decode_compressed ( & self , cam : & Camera , width : usize , height : usize ) -> Result < Vec < u16 > , String > {
192
- let mut out = vec ! [ 0 as u16 ; width* height] ;
192
+ let mut out = alloc_image ! ( width, height) ;
193
193
194
194
let dectable = fetch_tag ! ( self . ciff, CiffTag :: DecoderTable ) . get_usize ( 0 ) ;
195
195
if dectable > 2 {
Original file line number Diff line number Diff line change @@ -61,7 +61,7 @@ impl<'a> DcrDecoder<'a> {
61
61
}
62
62
63
63
fn decode_kodak65000 ( buf : & [ u8 ] , curve : & LookupTable , width : usize , height : usize ) -> Vec < u16 > {
64
- let mut out: Vec < u16 > = vec ! [ 0 ; width* height] ;
64
+ let mut out: Vec < u16 > = alloc_image ! ( width, height) ;
65
65
let mut input = ByteStream :: new ( buf, LITTLE_ENDIAN ) ;
66
66
67
67
let mut random: u32 = 0 ;
Original file line number Diff line number Diff line change @@ -200,7 +200,7 @@ impl<'a> DngDecoder<'a> {
200
200
}
201
201
let offset = offsets. get_usize ( 0 ) ;
202
202
let src = & self . buffer [ offset..] ;
203
- let mut out = vec ! [ 0 as u16 ; width* height] ;
203
+ let mut out = alloc_image ! ( width, height) ;
204
204
let decompressor = try!( LjpegDecompressor :: new ( src) ) ;
205
205
try!( decompressor. decode ( & mut out, 0 , width, width, height) ) ;
206
206
Ok ( out)
Original file line number Diff line number Diff line change @@ -82,7 +82,7 @@ impl<'a> KdcDecoder<'a> {
82
82
}
83
83
84
84
fn decode_dc120 ( src : & [ u8 ] , width : usize , height : usize ) -> Vec < u16 > {
85
- let mut out = vec ! [ 0u16 ; width* height] ;
85
+ let mut out = alloc_image ! ( width, height) ;
86
86
87
87
let mul: [ usize ; 4 ] = [ 162 , 192 , 187 , 92 ] ;
88
88
let add: [ usize ; 4 ] = [ 0 , 636 , 424 , 212 ] ;
Original file line number Diff line number Diff line change @@ -25,6 +25,18 @@ macro_rules! fetch_ifd {
25
25
) ;
26
26
}
27
27
28
+ macro_rules! alloc_image {
29
+ ( $width: expr, $height: expr) => (
30
+ {
31
+ if $width * $height > 500000000 {
32
+ panic!( "rawloader: surely there's no such thing as a >500MP image!" ) ;
33
+ }
34
+ let mut out: Vec <u16 > = vec![ 0 ; $width * $height] ;
35
+ out
36
+ }
37
+ ) ;
38
+ }
39
+
28
40
extern crate toml;
29
41
use self :: toml:: Value ;
30
42
mod image;
Original file line number Diff line number Diff line change @@ -89,7 +89,7 @@ impl<'a> MosDecoder<'a> {
89
89
let decompressor = try!( LjpegDecompressor :: new_full ( src, true , true ) ) ;
90
90
let ljpegout = try!( decompressor. decode_leaf ( width, height) ) ;
91
91
if cam. find_hint ( "interlaced" ) {
92
- let mut out = vec ! [ 0 as u16 ; width* height] ;
92
+ let mut out = alloc_image ! ( width, height) ;
93
93
for ( row, line) in ljpegout. chunks_exact ( width) . enumerate ( ) {
94
94
let orow = if row & 1 == 1 { height-1 -row/2 } else { row/2 } ;
95
95
out[ orow* width .. ( orow+1 ) * width] . copy_from_slice ( line) ;
Original file line number Diff line number Diff line change @@ -285,7 +285,7 @@ impl<'a> NefDecoder<'a> {
285
285
}
286
286
let curve = LookupTable :: new ( & points[ 0 ..max] ) ;
287
287
288
- let mut out = vec ! [ 0 as u16 ; width * height] ;
288
+ let mut out = alloc_image ! ( width, height) ;
289
289
let mut pump = BitPumpMSB :: new ( src) ;
290
290
let mut random = pump. peek_bits ( 24 ) ;
291
291
You can’t perform that action at this time.
0 commit comments