File: bug00375.phpt

package info (click to toggle)
php-mongo 1.5.7-1
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 11,040 kB
  • ctags: 2,802
  • sloc: ansic: 17,632; xml: 2,195; php: 1,630; pascal: 330; makefile: 52; sh: 39
file content (37 lines) | stat: -rw-r--r-- 977 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
--TEST--
Test for PHP-375: GridFS segfaults when there are more chunks than expected
--SKIPIF--
<?php require_once "tests/utils/standalone.inc"; ?>
--FILE--
<?php
require_once "tests/utils/server.inc";

$m = new_mongo_standalone();
$gridfs = $m->selectDb(dbname())->getGridfs();
$gridfs->remove();

$id = $gridfs->put(__FILE__);
$coll = $m->selectDB(dbname())->selectCollection("fs.chunks");

// Fetch the first (only) chunk
$chunk = $coll->find(array("files_id" => $id))->getNext();
// Unset the id and bump the chunk# to create unexpectedly many chunks
unset($chunk["_id"]);
$chunk["n"]++;
$coll->insert($chunk);


// Now fetch the inserted file
$file = $gridfs->findOne(array("_id" => $id));

// Throws exception about to many chunks
try {
    $file->getBytes();
} catch(MongoGridFSException $e) {
    var_dump($e->getMessage(), $e->getCode());
}
?>
--EXPECTF--
string(%d) "There is more data associated with this file than the metadata specifies (reading chunk 1)"
int(1)