Rails/ruby seems to be interpreting the content in "render :file" request

Got a weird situation:

I send a pdf to the user using this line in my controller:
format.pdf { render :file => pdf_file_path }

This has been working fine. But, on one specific file (meaning specific file content) I get this error, which makes it look like Ruby via Rails is trying to interpret the content of the file as code. Because other files are downloading fine, and from the error message I conclude that Ruby is in fact trying to interpret the file content:

exception.message: "compile error\n\\n /media/lqidatastore/production/temp/297_standard_view.pdf:736: Invalid char \\\\225' in expression\\n\\\n /media/lqidatastore/production/temp/297_standard_view.pdf:736: Invalid char \\263’ in expression\n\\n /media/lqidatastore/production/temp/297_standard_view.pdf:736: syntax error, unexpected tIDENTIFIER, expecting kEND\n\\n ; Y\\ao0\\x01\\a\\x83\\x16\\x97a\\x1E\\\\\\xA3\\x98\\e\\xB58\\x8CsV\\xB5\\xE0\\xBC9\x95\xB3p\x84\xD2\xEA!\x84+\xD3\xE2\xF7H\xD3j\xB0\x8Ch\vc\x1D[\x0F\xF4\x19t\n

The actual error is longer but you get the point. There is no line 736 in my controller, but there is in the pdf file:

Line 736:
∏Õ3"ögD4œàhû—<¢yFDÛåàÊÕ3"öÁB¥¿àhÅ—#¢FD\à-0"ZD¥¿àhÅ—"#¢EFDãåà-r!ZdD¥»àhë—"#¢E&DÉö—Z€LÅ÷ŸÊ ¥÷6S†µ∂yç—Z€lÅ∆áh≠m∂@„B4≈àhä—#¢)FDS\à¶M1"öbD4≈àhä—4#¢iFD”åà¶Ms!cÕ�0÷�cÕ�0÷�WÕ�0÷�cÕ�0÷�cÕ�p’�cÕ�0÷�cÕ�0÷�WÕ�0÷�cÕ�0÷�cÕ�p’�cÕ�0÷�cÕ�0÷�WÕ�0÷�cÕ�0÷�cÕ�†öÅmæpøp‡ã€›ÂµÜÊ·∑*’˛˛Y˜Ì6ı:ı@ßflæØ~N¡Æ~©n?Óîn~Ÿµ\u-Í°E=ÔZ©–QµÑ∂%<4Ëm√´€›õ#2⁄~Áírùa3ÓÏ®zW˙˛ŸkÄ`tçGÉ¿£˚í¬É&F«òzÍÅz5µ¨qÔ:/ÌRwQ¿‡”‡ñ∫¨a¨ÍÎ∂!NáatÃÃpí\ÏP´Ô/vò⁄ôπÿhÍóìH4ç&Iwõyo—ıf˝d Ò2/‹{t°ë;¯z†kàMœ‹t¬‚HËÇ≈?jÙ±i˝uı˜«—çé1Ë¥∫ûûÖÓ2’DÏ牱EA-3„P|lkçu<;WÙÁ-$Ïbî}ÑÊ≈4bAx∫Möa|ö}#LBdÉ◊ZOßüCÃÜ∏yT[tIÃw§57Éñ’”)ã©e/Ó.ÕY<â◊05:Ô®ZCÜË¢Ño¯2Õ�’

So the million dollar question is what could make Rails decide to interpret the content of a file which we are asking for it to pass down to the user? And better yet, is there a way I can tell Rails “hey, this is a file, lay off”?

David

Got a weird situation:

I send a pdf to the user using this line in my controller:
format.pdf { render :file => pdf_file_path }

This has been working fine. But, on one specific file (meaning specific file
content) I get this error, which makes it look like Ruby via Rails is trying
to interpret the content of the file as code. Because other files are
downloading fine, and from the error message I conclude that Ruby is in fact
trying to interpret the file content:

exception.message: \"compile error\\n\\\n
/media/lqidatastore/production/temp/297_standard_view.pdf:736: Invalid char
`\\\\225' in expression\\n\\\n
/media/lqidatastore/production/temp/297_standard_view.pdf:736: Invalid char
`\\\\263' in expression\\n\\\n

Are you sure it is a rails error? Does it have a conventional ruby
stack trace dump? If so can you post it? What do you see in the
rails log?

Colin

Got a weird situation:

I send a pdf to the user using this line in my controller:
format.pdf { render :file => pdf_file_path }

This has been working fine. But, on one specific file (meaning specific file
content) I get this error, which makes it look like Ruby via Rails is trying
to interpret the content of the file as code. Because other files are
downloading fine, and from the error message I conclude that Ruby is in fact
trying to interpret the file content:

exception.message: \"compile error\\n\\\n
/media/lqidatastore/production/temp/297_standard_view.pdf:736: Invalid char
`\\\\225' in expression\\n\\\n
/media/lqidatastore/production/temp/297_standard_view.pdf:736: Invalid char
`\\\\263' in expression\\n\\\n
/media/lqidatastore/production/temp/297_standard_view.pdf:736: syntax error,
unexpected tIDENTIFIER, expecting kEND\\n\\\n ;
Y`\\ao0\\x01\\a\\x83\\x16\\x97a\\x1E\\\\\\xA3\\x98\\e\\xB58\\x8CsV\\xB5\\xE 0\\xBC9`\\x95\\xB3p\\x84\\xD2\\xEA!\\x84+\\xD3\\xE2\\xF7H\\xD3j\\xB0\\x8Ch\ \vc\\x1D[\\x0F\\xF4\\x19t\\n

The actual error is longer but you get the point. There is no line 736 in my
controller, but there is in the pdf file:

Line 736:
∏ Õ3"ögD4œàhû —< ¢yFDÛåàÊ Õ3"öÁB¥¿àhÅ — #¢ FD \à -0"Z`D¥¿àhÅ —"#¢EFDãåà -r!ZdD¥»àhë —"#¢E&DÉö —Z€LÅ÷ŸÊ
¥÷6S†µ∂y ç —Z€lÅ∆áh≠m∂@„B4≈àhä — #¢)FDS\චM1"öbD4≈àhä —4#¢iFD”åචMs! cÕ 0÷ cÕ 0÷ WÕ 0÷ cÕ 0÷ cÕ p’ cÕ 0÷ cÕ 0÷ WÕ 0÷ cÕ 0÷ cÕ p’ cÕ 0÷ cÕ 0÷ WÕ 0÷ cÕ 0÷ cÕ †öÅm æpøp‡ã€›ÂµÜÊ· ∑ *’˛˛Y˜Ì6ı:ı@ß flæØ~N¡Æ~©n?Óîn~Ÿµ\u-Í°E=ÔZ`© –Q µÑ∂%<4Ë m√´€›õ# 2⁄~Áírùa3 ÓÏ®z W˙˛ Ÿ kÄ`tçG É ¿£˚í¬É&F« òzÍÅz5µ¨qÔ:/ÌRwQ¿‡”‡ñ∫ ¨a¨ÍÎ∂!NáatÃÃpí\ÏP´Ô/vò⁄ôπÿhÍóìH4 ç&Iwõyo —ıf˝d
Ò 2/ ‹{t°ë;¯z†kàMœ‹t¬‚HËÇ≈?jÙ±i˝ u ı˜«—çé1Ë¥∫ûûÖÓ2'DÏç ‰±E A-3 „P |lkçu<;WÙÁ -$Ïbî}Ñ Ê≈4bAx∫M ö a|ö}#LBdÉ◊ZOßüCÃÜ∏ yT[t IÃw§5 7Éñ'”)ã©e/Ó.ÕY<â◊05:Ô ®ZCÜË¢ Ño¯2Õ '

So the million dollar question is what could make Rails decide to interpret
the content of a file which we are asking for it to pass down to the user?
And better yet, is there a way I can tell Rails "hey, this is a file, lay
off"?

If you actually just want to send a file, use send_file. render :file
means 'here is a template, please execute it".

Fred

Got a weird situation:

I send a pdf to the user using this line in my controller:

format.pdf { render :file => pdf_file_path }

This has been working fine. But, on one specific file (meaning specific file

content) I get this error, which makes it look like Ruby via Rails is trying

to interpret the content of the file as code. Because other files are

downloading fine, and from the error message I conclude that Ruby is in fact

trying to interpret the file content:

exception.message: "compile error\n\\n

/media/lqidatastore/production/temp/297_standard_view.pdf:736: Invalid char

`\\225’ in expression\n\\n

/media/lqidatastore/production/temp/297_standard_view.pdf:736: Invalid char

`\\263’ in expression\n\\n

/media/lqidatastore/production/temp/297_standard_view.pdf:736: syntax error,

unexpected tIDENTIFIER, expecting kEND\n\\n ;

Y\\ao0\\x01\\a\\x83\\x16\\x97a\\x1E\\\\\\xA3\\x98\\e\\xB58\\x8CsV\\xB5\\xE 0\\xBC9\x95\xB3p\x84\xD2\xEA!\x84+\xD3\xE2\xF7H\xD3j\xB0\x8Ch\ \vc\x1D[\x0F\xF4\x19t\n

The actual error is longer but you get the point. There is no line 736 in my

controller, but there is in the pdf file:

Line 736:

∏ Õ3"ögD4œàhû —< ¢yFDÛåàÊ Õ3"öÁB¥¿àhÅ — #¢ FD \à -0"Z`D¥¿àhÅ —"#¢EFDãåà -r!ZdD¥»àhë —"#¢E&DÉö —Z€LÅ÷ŸÊ

¥÷6S†µ∂y ç —Z€lÅ∆áh≠m∂@„B4≈àhä — #¢)FDS\චM1"öbD4≈àhä —4#¢iFD”åචMs! cÕ 0÷ cÕ 0÷ WÕ 0÷ cÕ 0÷ cÕ p’ cÕ 0÷ cÕ 0÷ WÕ 0÷ cÕ 0÷ cÕ p’ cÕ 0÷ cÕ 0÷ WÕ 0÷ cÕ 0÷ cÕ †öÅm æpøp‡ã€›ÂµÜÊ· ∑ *’˛˛Y˜Ì6ı:ı@ß flæØ~N¡Æ~©n?Óîn~Ÿµ\u-Í°E=ÔZ© –Q µÑ∂%<4Ë m√´€›õ# 2⁄~Áírùa3 ÓÏ®z W˙˛ Ÿ kÄtçG É ¿£˚í¬É&F« òzÍÅz5µ¨qÔ:/ÌRwQ¿‡”‡ñ∫ ¨a¨ÍÎ∂!NáatÃÃpí\ÏP´Ô/vò⁄ôπÿhÍóìH4 ç&Iwõyo —ıf˝d

Ò 2/ ‹{t°ë;¯z†kàMœ‹t¬‚HËÇ≈?jÙ±i˝ u ı˜«—çé1Ë¥∫ûûÖÓ2’DÏç ‰±E A-3 „P |lkçu<;WÙÁ -$Ïbî}Ñ Ê≈4bAx∫M ö a|ö}#LBdÉ◊ZOßüCÃÜ∏ yT[t IÃw§5 7Éñ’”)ã©e/Ó.ÕY<â◊05:Ô ®ZCÜË¢ Ño¯2Õ ’

So the million dollar question is what could make Rails decide to interpret

the content of a file which we are asking for it to pass down to the user?

And better yet, is there a way I can tell Rails "hey, this is a file, lay

off"?

If you actually just want to send a file, use send_file. render :file

means 'here is a template, please execute it".

Thanks, right on. One question though: if I call “render :text = > response” does this also get interpreted? If I am returning xml (which has an embeded pdf doc), am I better of using send_data or render :text?

On Fri, Dec 10, 2010 at 6:29 AM, Frederick Cheung <

Thanks, right on. One question though: if I call "render :text = > response"
does this also get interpreted? If I am returning xml (which has an embeded
pdf doc), am I better of using send_data or render :text?

render :text will just dump what you pass straight into the response
( it's what send_data uses internally).
send_data is mostly a convenience that sets headers like Content-
disposition for you. If you have an actual file then send_file can be
more efficient if you use the x-send-file or stream options since
those don't entail loading the whole file into your rails process.

Fred

On Fri, Dec 10, 2010 at 6:29 AM, Frederick Cheung <

Thanks, right on. One question though: if I call “render :text = > response”

does this also get interpreted? If I am returning xml (which has an embeded

pdf doc), am I better of using send_data or render :text?

render :text will just dump what you pass straight into the response

( it’s what send_data uses internally).

send_data is mostly a convenience that sets headers like Content-

disposition for you. If you have an actual file then send_file can be

more efficient if you use the x-send-file or stream options since

those don’t entail loading the whole file into your rails process.

Perfect, thanks… looks like problem solved!