Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CentOS 6.8 でAVIファイルがアップロードできない #134

Closed
ClumsySmile opened this issue Feb 2, 2017 · 4 comments
Closed

CentOS 6.8 でAVIファイルがアップロードできない #134

ClumsySmile opened this issue Feb 2, 2017 · 4 comments
Labels

Comments

@ClumsySmile
Copy link

※ 3.0.1 でリリースされたバージョンで確認。

CentOS 6.8環境で AVI ファイルをアップロードしたが、アップロード不可のファイルと認識されてしまう。
Videos/Model/Behavior/VideoValidationBehavior.php の mimetype 判定処理が原因。

Videos/Model/Video.php の VIDEO_MIME_TYPE に 「video/x-msvideo」 を追加することによって回避は可能だが、環境により mymetype は異なるため、拡張子による判断にした方が無難。

@akagane99
Copy link
Contributor

ご指摘感謝。
修正しようと思います。

MIME_TYPEでチェックしてるのは、拡張子偽装対応のためなんです。
なので、VIDEO_MIME_TYPE を修正しようと思ってます。

@akagane99
Copy link
Contributor

調査内容。
とりあえずwikipediaでmimetypeをチェック。
本来mimetypeはRFCで規定
https://ja.wikipedia.org/wiki/Multipurpose_Internet_Mail_Extensions

--- .avi

https://ja.wikipedia.org/wiki/Audio_Video_Interleave

video/avi
video/msvideo
video/x-msvideo

--- .mpg, .mpeg, .mpe

https://it.wikipedia.org/wiki/MPEG

video/mpeg, video/x-mpeg,

--- .mov

https://ja.wikipedia.org/wiki/QuickTime

video/quicktime

--- flv

https://ja.wikipedia.org/wiki/Flash_Video

video/x-flv

--- mp4

https://ja.wikipedia.org/wiki/MP4

video/mp4

https://tools.ietf.org/html/rfc4337#section-2

a) if the file contains neither visual nor audio presentations, but
only, for example, MPEG-J or MPEG-7, use application/mp4;

(機械翻訳) a)ファイルにビジュアルプレゼンテーションもオーディオプレゼンテーションも含まれていない場合
たとえばMPEG-JまたはMPEG-7のみ、application / mp4を使用します。

application/mp4は入れない。

--- wmv

https://ja.wikipedia.org/wiki/Windows_Media_Video

video/x-ms-wmv

--- .asf .wmv

https://ja.wikipedia.org/wiki/Advanced_Systems_Format

拡張子 .asf .wma .wmv
MIME Type video/x-ms-asf

--- .wmx(対応しない)

今回は対応しない。
wmx, winodws10で再生できなかった。

wmxサンプル
http://www.gomplayer.jp/player/support/sample.html

  • コンバートできるかな
    • /usr/bin/ffmpeg -y -i sample_wmv_wmv9_wma9.wmx -ar 44100 -vcodec libx264 -r 30 -b 500k -strict -2 sample_wmv_wmv9_wma9.wmx.mp4
      • → 変換できた。変換後mp4再生できた
      • でも画面からアップロードするとなぜか、$noConvert['UploadFile']の中身がなくなる。アプリケーションの問題っぽいけど、今回は対応しない

debuglog

2017-02-12 12:08:12 Debug: Array
(
    [0] => /usr/bin/ffmpeg -y -i '/var/www/app/app/webroot//' -ar 48000 -vcodec libx264 -r 30 -b 500k -strict -2 '/var/www/app/app/tmp/0bd1fa233c31fdf0ec608ab5905cf343/.mp4' 2>&1
    [1] => Array
        (
            [0] => ffmpeg version 0.8.17-4:0.8.17-0ubuntu0.12.04.2, Copyright (c) 2000-2014 the Libav developers
            [1] =>   built on Apr  1 2016 14:24:20 with gcc 4.6.3
            [2] => The ffmpeg program is only provided for script compatibility and will be removed
            [3] => in a future release. It has been deprecated in the Libav project to allow for
            [4] => incompatible command line syntax improvements in its replacement called avconv
            [5] => (see Changelog for details). Please use avconv instead.
            [6] => /var/www/app/app/webroot//: Operation not permitted
        )

    [2] => 1
)

@po-
Copy link

po- commented Feb 16, 2017

PHP の mimetype の判定は、
Linux のコマンド 'file' の様にファイルヘッダーを見て判断しているわけではなく、
拡張子で判断しているだけと思われます。
(ウラ取れなかったですが、 http://php.net/manual/ja/function.mime-content-type.php#116793 様に行われている例もあります)
そのため、「拡張子偽装」を避ける意味には、ならないかと思われます。

試しにテキストファイルの拡張子を '.avi' としたところ、ある環境の php では 'video/x-msvideo' と判定されます。

@akagane99
Copy link
Contributor

連絡ありがとう。
ありゃ、そうなの?

ubuntu12.04でmime typeのバリデーションチェックを確認した時は、拡張子偽装したら、ちゃんとチェックしてくれたんだけどなぁ。

気になって調べてみました。
mime typeのバリデーションチェックはcakephp2のValidation::mimeType()を使ってて、その中でmime_content_type()は使ってなかったので、ご連絡もらった問題はなさそうです。
https://github.com/cakephp/cakephp/blob/2.x/lib/Cake/Utility/Validation.php#L949

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants