@@ -749,6 +749,33 @@ namespace
749749 }
750750 }
751751
752+ USHORT validatePageSize (SLONG pageSize)
753+ {
754+ USHORT actualPageSize = DEFAULT_PAGE_SIZE;
755+
756+ if (pageSize > 0 )
757+ {
758+ for (SLONG size = MIN_PAGE_SIZE; size <= MAX_PAGE_SIZE; size <<= 1 )
759+ {
760+ if (pageSize <= size)
761+ {
762+ pageSize = size;
763+ break ;
764+ }
765+ }
766+
767+ if (pageSize > MAX_PAGE_SIZE)
768+ pageSize = MAX_PAGE_SIZE;
769+
770+ fb_assert (pageSize <= MAX_USHORT);
771+ actualPageSize = (USHORT) pageSize;
772+ }
773+
774+ fb_assert (actualPageSize % PAGE_SIZE_BASE == 0 );
775+ fb_assert (actualPageSize >= MIN_PAGE_SIZE && actualPageSize <= MAX_PAGE_SIZE);
776+
777+ return actualPageSize;
778+ }
752779
753780 class DefaultCallback : public AutoIface <ICryptKeyCallbackImpl<DefaultCallback, CheckStatusWrapper> >
754781 {
@@ -3005,18 +3032,7 @@ JAttachment* JProvider::createDatabase(CheckStatusWrapper* user_status, const ch
30053032
30063033 attachment->att_client_charset = attachment->att_charset = options.dpb_interp ;
30073034
3008- if (options.dpb_page_size <= 0 ) {
3009- options.dpb_page_size = DEFAULT_PAGE_SIZE;
3010- }
3011-
3012- SLONG page_size = MIN_PAGE_SIZE;
3013- for (; page_size < MAX_PAGE_SIZE; page_size <<= 1 )
3014- {
3015- if (options.dpb_page_size < page_size << 1 )
3016- break ;
3017- }
3018-
3019- dbb->dbb_page_size = (page_size > MAX_PAGE_SIZE) ? MAX_PAGE_SIZE : page_size;
3035+ dbb->dbb_page_size = validatePageSize (options.dpb_page_size );
30203036
30213037 TRA_init (attachment);
30223038
@@ -7634,20 +7650,22 @@ static JAttachment* create_attachment(const PathName& alias_name,
76347650
76357651static void check_single_maintenance (thread_db* tdbb)
76367652{
7637- Database* const dbb = tdbb->getDatabase ();
7653+ const auto dbb = tdbb->getDatabase ();
7654+ const auto attachment = tdbb->getAttachment ();
76387655
76397656 const ULONG ioBlockSize = dbb->getIOBlockSize ();
76407657 const ULONG headerSize = MAX (RAW_HEADER_SIZE, ioBlockSize);
76417658
76427659 HalfStaticArray<UCHAR, RAW_HEADER_SIZE + PAGE_ALIGNMENT> temp;
7643- UCHAR* header_page_buffer = temp.getAlignedBuffer (headerSize, ioBlockSize);
7660+ UCHAR* const header_page_buffer = temp.getAlignedBuffer (headerSize, ioBlockSize);
76447661
7645- Ods::header_page* const header_page = reinterpret_cast <Ods::header_page*>(header_page_buffer);
7662+ if (!PIO_header (tdbb, header_page_buffer, headerSize))
7663+ ERR_post (Arg::Gds (isc_bad_db_format) << Arg::Str (attachment->att_filename ));
76467664
7647- PIO_header (tdbb, header_page_buffer, headerSize );
7665+ const auto header_page = reinterpret_cast <Ods::header_page*>(header_page_buffer );
76487666
76497667 if (header_page->hdr_shutdown_mode == Ods::hdr_shutdown_single)
7650- ERR_post (Arg::Gds (isc_shutdown) << Arg::Str (tdbb-> getAttachment () ->att_filename ));
7668+ ERR_post (Arg::Gds (isc_shutdown) << Arg::Str (attachment ->att_filename ));
76517669}
76527670
76537671
0 commit comments