Skip to content

Commit

Permalink
Blocks in OST 2013 files are aligned on 512-byte boundaries instead o…
Browse files Browse the repository at this point in the history
…f 64-byte boundaries
  • Loading branch information
Jmcleodfoss committed Jul 22, 2020
1 parent ff80486 commit 17a13ae
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions pst/src/main/java/io/github/jmcleodfoss/pst/BlockBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* @see <a href="https://docs.microsoft.com/en-us/openspecs/office_file_formats/ms-pst/8f34ce81-7a04-4a31-ba48-e05543daa77f">MS-PST Section 2.2.2.8.3: Block Types</a>
* @see <a href="https://docs.microsoft.com/en-us/openspecs/office_file_formats/ms-pst/d0e6fbaf-00e3-4d4d-bea8-8ab3cdb4fde6">MS-PST Section 2.2.2.8.3.1: Data Blocks</a>
* @see <a href="https://docs.microsoft.com/en-us/openspecs/office_file_formats/ms-pst/45688317-46fb-4038-9ed3-b845d80bdabb">MS-PST Section 2.2.8.3.2: Data Tree</a>
* @see <a href="https://blog.mythicsoft.com/ost-2013-file-format-the-missing-documentation/">OST 2013 file format the missing documentation blog entry</a>
*/
abstract class BlockBase
{
Expand All @@ -12,6 +13,11 @@ abstract class BlockBase
*/
private static final int BASE_BYTES = 64;

/** All blocks are a multiple of ({@value}) in size for OST 2013 files.
* @see <a href="https://blog.mythicsoft.com/ost-2013-file-format-the-missing-documentation/">OST 2013 file format the missing documentation blog entry</a>
*/
private static final int BASE_BYTES_OST_2013 = 512;

/** The maximum number of bytes in a block is {@value} for an ANSI or Unicode file
* @see <a href="https://docs.microsoft.com/en-us/openspecs/office_file_formats/ms-pst/a9c1981d-d1ea-457c-b39e-dc7fb0eb95d4">MS-PST Section 2.2.2.8: Blocks</a>
*/
Expand All @@ -34,13 +40,17 @@ abstract class BlockBase
* @param numBytes The number of data bytes in the block.
* @param pstFile The PST file input data stream, {@link Header}, etc
* @return The size of the block with padding given the target size in bytes.
* @see <a href="https://docs.microsoft.com/en-us/openspecs/office_file_formats/ms-pst/a9c1981d-d1ea-457c-b39e-dc7fb0eb95d4">MS-PST Section 2.2.2.8: Blocks</a>
* @see <a href="https://blog.mythicsoft.com/ost-2013-file-format-the-missing-documentation/">OST 2013 file format the missing documentation blog entry</a>
*/
protected static int blockSize(final int numBytes, final PSTFile pstFile)
{
int requiredSize = numBytes + BlockTrailer.size(pstFile);
if (requiredSize % BASE_BYTES == 0)

final int baseBytes = pstFile.header.fileFormat.index == FileFormat.Index.OST_2013 ? BASE_BYTES_OST_2013 : BASE_BYTES;
if (requiredSize % baseBytes == 0)
return requiredSize;
return ((requiredSize/BASE_BYTES) + 1) * BASE_BYTES;
return ((requiredSize/baseBytes) + 1) * baseBytes;
}

/** Return the data within this block, returned as a ByteBuffer.
Expand Down

0 comments on commit 17a13ae

Please sign in to comment.