Ticket #331 (closed バグ指摘: 修正済)
SC_Utils::sfEncodeFileで無限ループする可能性
| Reported by: | adachi | Owned by: | nanasess |
|---|---|---|---|
| Priority: | 中 | Milestone: | EC-CUBE2.3.0 |
| Component: | フロント | Version: | 2.1.2(正式版) |
| Keywords: | SC_Utils sfEncodeFile 無限ループ | Cc: | |
| 修正済み: |
Description
SC_Utils::sfEncodeFile()で、ファイルポインタのチェックを行っていないため、 無限ループになる場合がある。
http://jp.php.net/manual/ja/function.feof.php
function sfEncodeFile($filepath, $enc_type, $out_dir) {
$ifp = fopen($filepath, "r");
$basename = basename($filepath);
$outpath = $out_dir . "enc_" . $basename;
$ofp = fopen($outpath, "w+");
while(!feof($ifp)) { // $ifpがfalseの場合がある
$line = fgets($ifp);
$line = mb_convert_encoding($line, $enc_type, "auto");
fwrite($ofp, $line);
}
fclose($ofp);
fclose($ifp);
return $outpath;
}
Change History
comment:1 Changed 18 years ago by nanasess
- Owner changed from somebody to nanasess
- Status changed from new to assigned
comment:2 Changed 18 years ago by nanasess
- Status changed from assigned to closed
- Resolution set to 修正済
下記のパッチで対応
Index: SC_Utils.php
===================================================================
--- SC_Utils.php (リビジョン 17488)
+++ SC_Utils.php (作業コピー)
@@ -1021,23 +1021,48 @@
return $ret;
}
+ /**
+ * テキストファイルの文字エンコーディングを変換する.
+ *
+ * $filepath に存在するテキストファイルの文字エンコーディングを変換する.
+ * 変換前の文字エンコーディングは, mb_detect_order で設定した順序で自動検出する.
+ * 変換後は, 変換前のファイル名に「enc_」というプレフィクスを付与し,
+ * $out_dir で指定したディレクトリへ出力する
+ *
+ * TODO $filepath のファイルがバイナリだった場合の扱い
+ * TODO fwrite などでのエラーハンドリング
+ *
+ * @access public
+ * @param string $filepath 変換するテキストファイルのパス
+ * @param string $enc_type 変換後のファイルエンコーディングの種類を表す文字列
+ * @param string $out_dir 変換後のファイルを出力するディレクトリを表す文字列
+ * @return string 変換後のテキストファイルのパス
+ */
function sfEncodeFile($filepath, $enc_type, $out_dir) {
$ifp = fopen($filepath, "r");
- $basename = basename($filepath);
- $outpath = $out_dir . "enc_" . $basename;
+ // 正常にファイルオープンした場合
+ if ($ifp !== false) {
- $ofp = fopen($outpath, "w+");
+ $basename = basename($filepath);
+ $outpath = $out_dir . "enc_" . $basename;
- while(!feof($ifp)) {
- $line = fgets($ifp);
- $line = mb_convert_encoding($line, $enc_type, "auto");
- fwrite($ofp, $line);
- }
+ $ofp = fopen($outpath, "w+");
- fclose($ofp);
- fclose($ifp);
+ while(!feof($ifp)) {
+ $line = fgets($ifp);
+ $line = mb_convert_encoding($line, $enc_type, "auto");
+ fwrite($ofp, $line);
+ }
+ fclose($ofp);
+ fclose($ifp);
+ }
+ // ファイルが開けなかった場合はエラーページを表示
+ else {
+ SC_Utils::sfDispError('');
+ exit;
+ }
return $outpath;
}
comu-ver2 には, r17489 でコミット済み
Note: See
TracTickets for help on using
tickets.
