~ubuntu-branches/debian/lenny/exiv2/lenny

« back to all changes in this revision

Viewing changes to samples/crwparse.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Mark Purcell
  • Date: 2008-06-21 08:23:53 UTC
  • mfrom: (1.1.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20080621082353-b1n4w08trwfwbfl4
Tags: 0.17.1-1
* New upstream release
  - Library transition cleared on debian-release/ d-d-a
* Version 0.17 also fixes:
  - CVE-2008-2696: DoS via metadata in images (Closes: #486328)
  - crashes when fed with wrong file (Closes: #485670)
* Urgency medium for CVE fix
* debian/patches/gcc4.3.diff unecessary for gcc-4.3
* Add /usr/share/bug/exiv2/presubj message for reportbug(1)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// ***************************************************************** -*- C++ -*-
 
2
// crwparse.cpp, $Rev: 1271 $
 
3
// Print the CIFF structure of a CRW file
 
4
 
 
5
#include <exiv2/crwimage.hpp>
 
6
#include <exiv2/futils.hpp>
 
7
 
 
8
#include <iostream>
 
9
 
 
10
int main(int argc, char* const argv[])
 
11
try {
 
12
    if (argc != 2) {
 
13
        std::cout << "Usage: " << argv[0] << " file\n";
 
14
        std::cout << "Print the CIFF structure of a CRW file\n";
 
15
        return 1;
 
16
    }
 
17
 
 
18
    Exiv2::FileIo io(argv[1]);
 
19
    if(io.open() != 0) {
 
20
        throw Exiv2::Error(9, io.path(), Exiv2::strError());
 
21
    }
 
22
    Exiv2::IoCloser closer(io);
 
23
 
 
24
    // Ensure that this is a CRW image
 
25
    if (!Exiv2::isCrwType(io, false)) {
 
26
        if (io.error() || io.eof()) throw Exiv2::Error(14);
 
27
        throw Exiv2::Error(33);
 
28
    }
 
29
 
 
30
    // Read the image into a memory buffer
 
31
    long len = io.size();
 
32
    Exiv2::DataBuf buf(len);
 
33
    io.read(buf.pData_, len);
 
34
    if (io.error() || io.eof()) throw Exiv2::Error(14);
 
35
 
 
36
    // Parse the image, starting with a CIFF header component
 
37
    Exiv2::CiffHeader::AutoPtr parseTree(new Exiv2::CiffHeader);
 
38
    parseTree->read(buf.pData_, buf.size_);
 
39
    parseTree->print(std::cout);
 
40
 
 
41
    return 0;
 
42
}
 
43
catch (Exiv2::AnyError& e) {
 
44
    std::cerr << e << "\n";
 
45
    return -1;
 
46
}