vfs: check userland buffers before reading them.
[haiku.git] / src / libs / print / libprint / PrintProcess.cpp
blob3f0dd55cac3aa6a757af6dfcefef6ea2265d9660
1 /*
2 * PrintProcess.cpp
3 * Copyright 1999-2000 Y.Takagi. All Rights Reserved.
4 */
6 #include <File.h>
7 #include <Picture.h>
8 #include <unistd.h>
10 #include "PrintProcess.h"
11 #include "DbgMsg.h"
14 PictureData::PictureData(BFile *file)
16 DBGMSG(("construct PictureData\n"));
17 DBGMSG(("1: current seek position = 0x%x\n", (int)file->Position()));
19 file->Read(&point, sizeof(BPoint));
20 file->Read(&rect, sizeof(BRect));
22 picture = new BPicture();
24 DBGMSG(("picture_data::point = %f, %f\n", point.x, point.y));
25 DBGMSG(("picture_data::rect = %f, %f, %f, %f\n",
26 rect.left, rect.top, rect.right, rect.bottom));
27 DBGMSG(("2: current seek position = 0x%x\n", (int)file->Position()));
29 picture->Unflatten(file);
31 DBGMSG(("3: current seek position = 0x%x\n", (int)file->Position()));
35 PictureData::~PictureData()
37 delete picture;
41 PageData::PageData()
43 fHollow = true;
47 PageData::PageData(BFile *file, bool reverse)
49 fFile = file;
50 fReverse = reverse;
51 fPictureCount = 0;
52 fRest = 0;
53 fOffset = 0;
54 fHollow = false;
56 if (reverse) {
57 file->Read(&fPictureCount, sizeof(int32));
58 DBGMSG(("picture_count = %" B_PRId32 "\n", fPictureCount));
59 fOffset = fFile->Position();
60 off_t o = fOffset;
61 // seek to start of next page
62 fFile->Read(&o, sizeof(o));
63 fFile->Seek(o, SEEK_SET);
68 bool
69 PageData::startEnum()
71 off_t offset;
72 uchar dummy[40];
74 if (fHollow)
75 return false;
77 if (fOffset == 0) {
78 fFile->Read(&fPictureCount, sizeof(int32));
79 DBGMSG(("picture_count = %" B_PRId32 "\n", fPictureCount));
80 fOffset = fFile->Position();
81 } else {
82 fFile->Seek(fOffset, SEEK_SET);
84 // skip page header
85 fFile->Seek(sizeof(offset) + sizeof(dummy), SEEK_CUR);
87 fRest = fPictureCount;
88 return fPictureCount > 0;
92 bool
93 PageData::enumObject(PictureData **picture_data)
95 if (fHollow || fPictureCount <= 0) {
96 *picture_data = NULL;
97 } else {
98 *picture_data = new PictureData(fFile);
99 if (--fRest > 0) {
100 return true;
103 return false;
107 SpoolData::SpoolData(BFile *file, int32 page_count, int32 nup, bool reverse)
109 DBGMSG(("nup = %" B_PRId32 "\n", nup));
110 DBGMSG(("page_count = %" B_PRId32 "\n", page_count));
111 DBGMSG(("reverse = %s\n", reverse ? "true" : "false"));
113 if (reverse) {
114 if (nup > 1) {
115 for (int32 page_index = 0; page_index < page_count; page_index++) {
116 if (page_index % nup == 0) {
117 fPages.push_front(new PageData(file, reverse));
118 fIt = fPages.begin();
119 fIt++;
120 } else {
121 fPages.insert(fIt, new PageData(file, reverse));
124 page_count = nup - page_count % nup;
125 if (page_count < nup) {
126 while (page_count--) {
127 fPages.insert(fIt, new PageData);
130 } else {
131 while (page_count--) {
132 fPages.push_front(new PageData(file, reverse));
135 } else {
136 while (page_count--) {
137 fPages.push_back(new PageData(file, reverse));
143 SpoolData::~SpoolData()
145 for (fIt = fPages.begin(); fIt != fPages.end(); fIt++) {
146 delete (*fIt);
151 bool
152 SpoolData::startEnum()
154 fIt = fPages.begin();
155 return true;
159 bool
160 SpoolData::enumObject(PageData **page_data)
162 *page_data = *fIt++;
163 if (fIt == fPages.end()) {
164 return false;
166 return true;